Code refactoring

This commit is contained in:
Jaex 2022-10-23 09:31:26 +03:00
parent ab2e37ad17
commit 092068f36b

View file

@ -59,45 +59,37 @@ private enum SetupJobs
private static SetupJobs Job = SetupJobs.Debug; private static SetupJobs Job = SetupJobs.Debug;
private static bool AppVeyor = false; private static bool AppVeyor = false;
private static string ParentDir => AppVeyor ? "." : @"..\..\..\"; private static string Configuration
private static string BinDir => Path.Combine(ParentDir, "ShareX", "bin");
private static string ReleaseDir => Path.Combine(BinDir, "Release");
private static string DebugDir => Path.Combine(BinDir, "Debug");
private static string SteamDir => Path.Combine(BinDir, "Steam");
private static string MicrosoftStoreDir => Path.Combine(BinDir, "MicrosoftStore");
private static string MicrosoftStoreDebugDir => Path.Combine(BinDir, "MicrosoftStoreDebug");
private static string ExecutablePath
{ {
get get
{ {
string dir; if (Job.HasFlag(SetupJobs.CreateDebug))
if (Job.HasFlag(SetupJobs.CreateSteamFolder))
{ {
dir = SteamDir; return "Debug";
} }
else if (Job.HasFlag(SetupJobs.CreateDebug)) else if (Job.HasFlag(SetupJobs.CreateSteamFolder))
{ {
dir = DebugDir; return "Steam";
} }
else if (Job.HasFlag(SetupJobs.CreateMicrosoftStoreFolder)) else if (Job.HasFlag(SetupJobs.CreateMicrosoftStoreFolder))
{ {
dir = MicrosoftStoreDir; return "MicrosoftStore";
} }
else if (Job.HasFlag(SetupJobs.CreateMicrosoftStoreDebugFolder)) else if (Job.HasFlag(SetupJobs.CreateMicrosoftStoreDebugFolder))
{ {
dir = MicrosoftStoreDebugDir; return "MicrosoftStoreDebug";
}
else
{
dir = ReleaseDir;
} }
return Path.Combine(dir, "ShareX.exe"); return "Release";
} }
} }
private static string ParentDir => AppVeyor ? "." : @"..\..\..\";
private static string BinDir => Path.Combine(ParentDir, "ShareX", "bin", Configuration);
private static string NativeMessagingHostDir => Path.Combine(ParentDir, "ShareX.NativeMessagingHost", "bin", Configuration);
private static string SteamLauncherDir => Path.Combine(ParentDir, "ShareX.Steam", "bin", Configuration);
private static string ExecutablePath => Path.Combine(BinDir, "ShareX.exe");
private static string OutputDir => Path.Combine(ParentDir, "Output"); private static string OutputDir => Path.Combine(ParentDir, "Output");
private static string PortableOutputDir => Path.Combine(OutputDir, "ShareX-portable"); private static string PortableOutputDir => Path.Combine(OutputDir, "ShareX-portable");
private static string DebugOutputDir => Path.Combine(OutputDir, "ShareX-debug"); private static string DebugOutputDir => Path.Combine(OutputDir, "ShareX-debug");
@ -110,10 +102,8 @@ private static string ExecutablePath
private static string PortableZipPath => Path.Combine(OutputDir, $"ShareX-{AppVersion}-portable.zip"); private static string PortableZipPath => Path.Combine(OutputDir, $"ShareX-{AppVersion}-portable.zip");
private static string DebugZipPath => Path.Combine(OutputDir, $"ShareX-{AppVersion}-debug.zip"); private static string DebugZipPath => Path.Combine(OutputDir, $"ShareX-{AppVersion}-debug.zip");
private static string SteamLauncherDir => Path.Combine(ParentDir, @"ShareX.Steam\bin\Release");
private static string SteamUpdatesDir => Path.Combine(SteamOutputDir, "Updates"); private static string SteamUpdatesDir => Path.Combine(SteamOutputDir, "Updates");
private static string SteamZipPath => Path.Combine(OutputDir, $"ShareX-{AppVersion}-Steam.zip"); private static string SteamZipPath => Path.Combine(OutputDir, $"ShareX-{AppVersion}-Steam.zip");
private static string NativeMessagingHostDir => Path.Combine(ParentDir, @"ShareX.NativeMessagingHost\bin\Release");
private static string RecorderDevicesSetupPath => Path.Combine(OutputDir, "Recorder-devices-setup.exe"); private static string RecorderDevicesSetupPath => Path.Combine(OutputDir, "Recorder-devices-setup.exe");
private static string MicrosoftStoreAppxPath => Path.Combine(OutputDir, $"ShareX-{AppVersion}.appx"); private static string MicrosoftStoreAppxPath => Path.Combine(OutputDir, $"ShareX-{AppVersion}.appx");
private static string FFmpegPath => Path.Combine(OutputDir, "ffmpeg.exe"); private static string FFmpegPath => Path.Combine(OutputDir, "ffmpeg.exe");
@ -151,12 +141,12 @@ private static void Main(string[] args)
if (Job.HasFlag(SetupJobs.CreatePortable)) if (Job.HasFlag(SetupJobs.CreatePortable))
{ {
CreateFolder(ReleaseDir, PortableOutputDir, SetupJobs.CreatePortable); CreateFolder(BinDir, PortableOutputDir, SetupJobs.CreatePortable);
} }
if (Job.HasFlag(SetupJobs.CreateDebug)) if (Job.HasFlag(SetupJobs.CreateDebug))
{ {
CreateFolder(DebugDir, DebugOutputDir, SetupJobs.CreateDebug); CreateFolder(BinDir, DebugOutputDir, SetupJobs.CreateDebug);
} }
if (Job.HasFlag(SetupJobs.CreateSteamFolder)) if (Job.HasFlag(SetupJobs.CreateSteamFolder))
@ -166,12 +156,12 @@ private static void Main(string[] args)
if (Job.HasFlag(SetupJobs.CreateMicrosoftStoreFolder)) if (Job.HasFlag(SetupJobs.CreateMicrosoftStoreFolder))
{ {
CreateFolder(MicrosoftStoreDir, MicrosoftStoreOutputDir, SetupJobs.CreateMicrosoftStoreFolder); CreateFolder(BinDir, MicrosoftStoreOutputDir, SetupJobs.CreateMicrosoftStoreFolder);
} }
if (Job.HasFlag(SetupJobs.CreateMicrosoftStoreDebugFolder)) if (Job.HasFlag(SetupJobs.CreateMicrosoftStoreDebugFolder))
{ {
CreateFolder(MicrosoftStoreDebugDir, MicrosoftStoreOutputDir, SetupJobs.CreateMicrosoftStoreDebugFolder); CreateFolder(BinDir, MicrosoftStoreOutputDir, SetupJobs.CreateMicrosoftStoreDebugFolder);
} }
if (Job.HasFlag(SetupJobs.CompileAppx)) if (Job.HasFlag(SetupJobs.CompileAppx))
@ -312,7 +302,7 @@ private static void CreateSteamFolder()
SetupHelpers.CopyFile(Path.Combine(SteamLauncherDir, "installscript.vdf"), SteamOutputDir); SetupHelpers.CopyFile(Path.Combine(SteamLauncherDir, "installscript.vdf"), SteamOutputDir);
SetupHelpers.CopyFiles(SteamLauncherDir, "*.dll", SteamOutputDir); SetupHelpers.CopyFiles(SteamLauncherDir, "*.dll", SteamOutputDir);
CreateFolder(SteamDir, SteamUpdatesDir, SetupJobs.CreateSteamFolder); CreateFolder(BinDir, SteamUpdatesDir, SetupJobs.CreateSteamFolder);
} }
private static void CreateFolder(string source, string destination, SetupJobs job) private static void CreateFolder(string source, string destination, SetupJobs job)