Move few methods to HelpersLib from Setup project

This commit is contained in:
Jaex 2018-03-03 00:17:01 +03:00
parent fa22ad8b2a
commit 68eda57ca5
3 changed files with 23 additions and 55 deletions

View file

@ -99,17 +99,17 @@ private static void Main(string[] args)
{ {
Console.WriteLine("ShareX setup started."); Console.WriteLine("ShareX setup started.");
if (Helpers.CheckArguments(args, "-AppVeyorRelease")) if (SetupHelpers.CheckArguments(args, "-AppVeyorRelease"))
{ {
AppVeyor = true; AppVeyor = true;
Job = SetupJobs.AppVeyorRelease; Job = SetupJobs.AppVeyorRelease;
} }
else if (Helpers.CheckArguments(args, "-AppVeyorSteam")) else if (SetupHelpers.CheckArguments(args, "-AppVeyorSteam"))
{ {
AppVeyor = true; AppVeyor = true;
Job = SetupJobs.AppVeyorSteam; Job = SetupJobs.AppVeyorSteam;
} }
else if (Helpers.CheckArguments(args, "-AppVeyorWindowsStore")) else if (SetupHelpers.CheckArguments(args, "-AppVeyorWindowsStore"))
{ {
AppVeyor = true; AppVeyor = true;
Job = SetupJobs.AppVeyorWindowsStore; Job = SetupJobs.AppVeyorWindowsStore;
@ -217,10 +217,10 @@ private static void CreateSteamFolder()
Directory.CreateDirectory(SteamOutputDir); Directory.CreateDirectory(SteamOutputDir);
Helpers.CopyFile(Path.Combine(SteamLauncherDir, "ShareX_Launcher.exe"), SteamOutputDir); SetupHelpers.CopyFile(Path.Combine(SteamLauncherDir, "ShareX_Launcher.exe"), SteamOutputDir);
Helpers.CopyFile(Path.Combine(SteamLauncherDir, "steam_appid.txt"), SteamOutputDir); SetupHelpers.CopyFile(Path.Combine(SteamLauncherDir, "steam_appid.txt"), SteamOutputDir);
Helpers.CopyFile(Path.Combine(SteamLauncherDir, "installscript.vdf"), SteamOutputDir); SetupHelpers.CopyFile(Path.Combine(SteamLauncherDir, "installscript.vdf"), SteamOutputDir);
Helpers.CopyFiles(SteamLauncherDir, "*.dll", SteamOutputDir); SetupHelpers.CopyFiles(SteamLauncherDir, "*.dll", SteamOutputDir);
CreateFolder(SteamDir, SteamUpdatesDir, SetupJobs.CreateSteamFolder); CreateFolder(SteamDir, SteamUpdatesDir, SetupJobs.CreateSteamFolder);
} }
@ -236,24 +236,24 @@ private static void CreateFolder(string source, string destination, SetupJobs jo
Directory.CreateDirectory(destination); Directory.CreateDirectory(destination);
Helpers.CopyFile(Path.Combine(source, "ShareX.exe"), destination); SetupHelpers.CopyFile(Path.Combine(source, "ShareX.exe"), destination);
Helpers.CopyFile(Path.Combine(source, "ShareX.exe.config"), destination); SetupHelpers.CopyFile(Path.Combine(source, "ShareX.exe.config"), destination);
if (job == SetupJobs.CreateWindowsStoreFolder || job == SetupJobs.CreateWindowsStoreDebugFolder) if (job == SetupJobs.CreateWindowsStoreFolder || job == SetupJobs.CreateWindowsStoreDebugFolder)
{ {
Helpers.CopyFiles(source, "*.dll", destination, new string[] { "7z.dll" }); SetupHelpers.CopyFiles(source, "*.dll", destination, new string[] { "7z.dll" });
} }
else else
{ {
Helpers.CopyFiles(source, "*.dll", destination); SetupHelpers.CopyFiles(source, "*.dll", destination);
} }
if (job == SetupJobs.CreateWindowsStoreDebugFolder) if (job == SetupJobs.CreateWindowsStoreDebugFolder)
{ {
Helpers.CopyFiles(source, "*.pdb", destination); SetupHelpers.CopyFiles(source, "*.pdb", destination);
} }
Helpers.CopyFiles(Path.Combine(ParentDir, "Licenses"), "*.txt", Path.Combine(destination, "Licenses")); SetupHelpers.CopyFiles(Path.Combine(ParentDir, "Licenses"), "*.txt", Path.Combine(destination, "Licenses"));
if (job != SetupJobs.CreateWindowsStoreFolder && job != SetupJobs.CreateWindowsStoreDebugFolder) if (job != SetupJobs.CreateWindowsStoreFolder && job != SetupJobs.CreateWindowsStoreDebugFolder)
{ {
@ -262,16 +262,16 @@ private static void CreateFolder(string source, string destination, SetupJobs jo
CompileISSFile("Recorder-devices-setup.iss"); CompileISSFile("Recorder-devices-setup.iss");
} }
Helpers.CopyFile(RecorderDevicesSetupPath, destination); SetupHelpers.CopyFile(RecorderDevicesSetupPath, destination);
Helpers.CopyFile(Path.Combine(NativeMessagingHostDir, "ShareX_NativeMessagingHost.exe"), destination); SetupHelpers.CopyFile(Path.Combine(NativeMessagingHostDir, "ShareX_NativeMessagingHost.exe"), destination);
} }
string[] languages = new string[] { "de", "es", "fr", "hu", "it-IT", "ko-KR", "nl-NL", "pt-BR", "ru", "tr", "vi-VN", "zh-CN", "zh-TW" }; string[] languages = new string[] { "de", "es", "fr", "hu", "it-IT", "ko-KR", "nl-NL", "pt-BR", "ru", "tr", "vi-VN", "zh-CN", "zh-TW" };
foreach (string language in languages) foreach (string language in languages)
{ {
Helpers.CopyFiles(Path.Combine(source, language), "*.resources.dll", Path.Combine(destination, "Languages", language)); SetupHelpers.CopyFiles(Path.Combine(source, language), "*.resources.dll", Path.Combine(destination, "Languages", language));
} }
if (job == SetupJobs.CreateSteamFolder) if (job == SetupJobs.CreateSteamFolder)
@ -284,7 +284,7 @@ private static void CreateFolder(string source, string destination, SetupJobs jo
} }
else if (job == SetupJobs.CreateWindowsStoreFolder || job == SetupJobs.CreateWindowsStoreDebugFolder) else if (job == SetupJobs.CreateWindowsStoreFolder || job == SetupJobs.CreateWindowsStoreDebugFolder)
{ {
Helpers.CopyFile(Path.Combine(DesktopBridgeHelperDir, "ShareX_DesktopBridgeHelper.exe"), destination); SetupHelpers.CopyFile(Path.Combine(DesktopBridgeHelperDir, "ShareX_DesktopBridgeHelper.exe"), destination);
Helpers.CopyAll(WindowsStorePackageFilesDir, destination); Helpers.CopyAll(WindowsStorePackageFilesDir, destination);
CopyFFmpeg(destination, false, true); CopyFFmpeg(destination, false, true);
} }
@ -309,24 +309,24 @@ private static void CopyFFmpeg(string destination, bool include32bit, bool inclu
{ {
if (!File.Exists(FFmpeg32bit)) if (!File.Exists(FFmpeg32bit))
{ {
string filename = Helpers.DownloadFile("http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-20171130-83ecdc9-win32-static.zip"); string filename = SetupHelpers.DownloadFile("http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-20171130-83ecdc9-win32-static.zip");
ZipManager.Extract(filename, "", new List<string>() { "ffmpeg.exe" }); ZipManager.Extract(filename, "", new List<string>() { "ffmpeg.exe" });
File.Move("ffmpeg.exe", FFmpeg32bit); File.Move("ffmpeg.exe", FFmpeg32bit);
} }
Helpers.CopyFile(FFmpeg32bit, destination); SetupHelpers.CopyFile(FFmpeg32bit, destination);
} }
if (include64bit) if (include64bit)
{ {
if (!File.Exists(FFmpeg64bit)) if (!File.Exists(FFmpeg64bit))
{ {
string filename = Helpers.DownloadFile("http://ffmpeg.zeranoe.com/builds/win64/static/ffmpeg-20171130-83ecdc9-win64-static.zip"); string filename = SetupHelpers.DownloadFile("http://ffmpeg.zeranoe.com/builds/win64/static/ffmpeg-20171130-83ecdc9-win64-static.zip");
ZipManager.Extract(filename, "", new List<string>() { "ffmpeg.exe" }); ZipManager.Extract(filename, "", new List<string>() { "ffmpeg.exe" });
File.Move("ffmpeg.exe", FFmpeg64bit); File.Move("ffmpeg.exe", FFmpeg64bit);
} }
Helpers.CopyFile(FFmpeg64bit, destination); SetupHelpers.CopyFile(FFmpeg64bit, destination);
} }
} }

View file

@ -32,7 +32,7 @@ You should have received a copy of the GNU General Public License
namespace ShareX.Setup namespace ShareX.Setup
{ {
internal class Helpers internal class SetupHelpers
{ {
public static string DownloadFile(string url) public static string DownloadFile(string url)
{ {
@ -90,33 +90,6 @@ public static void CopyFiles(string directory, string searchPattern, string toFo
CopyFiles(files, toFolder); CopyFiles(files, toFolder);
} }
public static void CopyAll(string sourceDirectory, string targetDirectory)
{
DirectoryInfo diSource = new DirectoryInfo(sourceDirectory);
DirectoryInfo diTarget = new DirectoryInfo(targetDirectory);
CopyAll(diSource, diTarget);
}
public static void CopyAll(DirectoryInfo source, DirectoryInfo target)
{
if (!Directory.Exists(target.FullName))
{
Directory.CreateDirectory(target.FullName);
}
foreach (FileInfo fi in source.GetFiles())
{
fi.CopyTo(Path.Combine(target.FullName, fi.Name), true);
}
foreach (DirectoryInfo diSourceSubDir in source.GetDirectories())
{
DirectoryInfo nextTargetSubDir = target.CreateSubdirectory(diSourceSubDir.Name);
CopyAll(diSourceSubDir, nextTargetSubDir);
}
}
private static void ProcessStart(string filePath, string arguments) private static void ProcessStart(string filePath, string arguments)
{ {
Console.WriteLine($"Process starting: {filePath} {arguments}"); Console.WriteLine($"Process starting: {filePath} {arguments}");
@ -147,10 +120,5 @@ public static bool CheckArguments(string[] args, string check)
return false; return false;
} }
public static void CreateEmptyFile(string path)
{
File.Create(path).Dispose();
}
} }
} }

View file

@ -72,7 +72,7 @@
<Compile Include="..\SharedAssemblyInfo.cs"> <Compile Include="..\SharedAssemblyInfo.cs">
<Link>Properties\SharedAssemblyInfo.cs</Link> <Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile> </Compile>
<Compile Include="Helpers.cs" /> <Compile Include="SetupHelpers.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>