mirror of
https://github.com/ShareX/ShareX.git
synced 2024-06-28 03:00:22 +12:00
Code refactoring
This commit is contained in:
parent
ec02677775
commit
b70d2587a2
|
@ -635,6 +635,77 @@ public static string CopyFile(string filePath, string destinationFolder, bool ov
|
|||
return null;
|
||||
}
|
||||
|
||||
public static void CopyFiles(string filePath, string destinationFolder)
|
||||
{
|
||||
CopyFiles(new string[] { filePath }, destinationFolder);
|
||||
}
|
||||
|
||||
public static void CopyFiles(IEnumerable<string> files, string destinationFolder)
|
||||
{
|
||||
if (!Directory.Exists(destinationFolder))
|
||||
{
|
||||
Directory.CreateDirectory(destinationFolder);
|
||||
}
|
||||
|
||||
foreach (string filePath in files)
|
||||
{
|
||||
string fileName = Path.GetFileName(filePath);
|
||||
string destinationFilePath = Path.Combine(destinationFolder, fileName);
|
||||
File.Copy(filePath, destinationFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
public static void CopyFiles(string sourceFolder, string destinationFolder, string searchPattern = "*", string[] ignoreFiles = null)
|
||||
{
|
||||
string[] files = Directory.GetFiles(sourceFolder, searchPattern);
|
||||
|
||||
if (ignoreFiles != null)
|
||||
{
|
||||
List<string> newFiles = new List<string>();
|
||||
|
||||
foreach (string file in files)
|
||||
{
|
||||
string fileName = Path.GetFileName(file);
|
||||
|
||||
if (ignoreFiles.All(x => !fileName.Equals(x, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
newFiles.Add(file);
|
||||
}
|
||||
}
|
||||
|
||||
files = newFiles.ToArray();
|
||||
}
|
||||
|
||||
CopyFiles(files, destinationFolder);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public static string MoveFile(string filePath, string destinationFolder, bool overwrite = true)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(filePath) && File.Exists(filePath) && !string.IsNullOrEmpty(destinationFolder))
|
||||
|
@ -745,33 +816,6 @@ public static string GetTempFilePath(string extension)
|
|||
return Path.ChangeExtension(path, extension);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public static void CreateEmptyFile(string filePath)
|
||||
{
|
||||
File.Create(filePath).Dispose();
|
||||
|
|
|
@ -312,10 +312,10 @@ private static void CreateSteamFolder()
|
|||
|
||||
Directory.CreateDirectory(SteamOutputDir);
|
||||
|
||||
SetupHelpers.CopyFile(Path.Combine(SteamLauncherDir, "ShareX_Launcher.exe"), SteamOutputDir);
|
||||
SetupHelpers.CopyFile(Path.Combine(SteamLauncherDir, "steam_appid.txt"), SteamOutputDir);
|
||||
SetupHelpers.CopyFile(Path.Combine(SteamLauncherDir, "installscript.vdf"), SteamOutputDir);
|
||||
SetupHelpers.CopyFiles(SteamLauncherDir, "*.dll", SteamOutputDir);
|
||||
FileHelpers.CopyFiles(Path.Combine(SteamLauncherDir, "ShareX_Launcher.exe"), SteamOutputDir);
|
||||
FileHelpers.CopyFiles(Path.Combine(SteamLauncherDir, "steam_appid.txt"), SteamOutputDir);
|
||||
FileHelpers.CopyFiles(Path.Combine(SteamLauncherDir, "installscript.vdf"), SteamOutputDir);
|
||||
FileHelpers.CopyFiles(SteamLauncherDir, SteamOutputDir, "*.dll");
|
||||
|
||||
CreateFolder(BinDir, SteamUpdatesDir, SetupJobs.CreateSteamFolder);
|
||||
}
|
||||
|
@ -331,16 +331,16 @@ private static void CreateFolder(string source, string destination, SetupJobs jo
|
|||
|
||||
Directory.CreateDirectory(destination);
|
||||
|
||||
SetupHelpers.CopyFile(Path.Combine(source, "ShareX.exe"), destination);
|
||||
SetupHelpers.CopyFile(Path.Combine(source, "ShareX.exe.config"), destination);
|
||||
SetupHelpers.CopyFiles(source, "*.dll", destination);
|
||||
FileHelpers.CopyFiles(Path.Combine(source, "ShareX.exe"), destination);
|
||||
FileHelpers.CopyFiles(Path.Combine(source, "ShareX.exe.config"), destination);
|
||||
FileHelpers.CopyFiles(source, destination, "*.dll");
|
||||
|
||||
if (job == SetupJobs.CreateDebug || job == SetupJobs.CreateMicrosoftStoreDebugFolder)
|
||||
{
|
||||
SetupHelpers.CopyFiles(source, "*.pdb", destination);
|
||||
FileHelpers.CopyFiles(source, destination, "*.pdb");
|
||||
}
|
||||
|
||||
SetupHelpers.CopyFiles(Path.Combine(ParentDir, "Licenses"), "*.txt", Path.Combine(destination, "Licenses"));
|
||||
FileHelpers.CopyFiles(Path.Combine(ParentDir, "Licenses"), Path.Combine(destination, "Licenses"), "*.txt");
|
||||
|
||||
if (job != SetupJobs.CreateMicrosoftStoreFolder && job != SetupJobs.CreateMicrosoftStoreDebugFolder)
|
||||
{
|
||||
|
@ -349,9 +349,9 @@ private static void CreateFolder(string source, string destination, SetupJobs jo
|
|||
CompileISSFile("Recorder-devices-setup.iss");
|
||||
}
|
||||
|
||||
SetupHelpers.CopyFile(RecorderDevicesSetupPath, destination);
|
||||
FileHelpers.CopyFiles(RecorderDevicesSetupPath, destination);
|
||||
|
||||
SetupHelpers.CopyFile(Path.Combine(NativeMessagingHostDir, "ShareX_NativeMessagingHost.exe"), destination);
|
||||
FileHelpers.CopyFiles(Path.Combine(NativeMessagingHostDir, "ShareX_NativeMessagingHost.exe"), destination);
|
||||
}
|
||||
|
||||
string[] languages = new string[] { "de", "es", "es-MX", "fa-IR", "fr", "hu", "id-ID", "it-IT", "ja-JP", "ko-KR", "nl-NL", "pl", "pt-BR", "pt-PT",
|
||||
|
@ -359,12 +359,12 @@ private static void CreateFolder(string source, string destination, SetupJobs jo
|
|||
|
||||
foreach (string language in languages)
|
||||
{
|
||||
SetupHelpers.CopyFiles(Path.Combine(source, language), "*.resources.dll", Path.Combine(destination, "Languages", language));
|
||||
FileHelpers.CopyFiles(Path.Combine(source, language), Path.Combine(destination, "Languages", language), "*.resources.dll");
|
||||
}
|
||||
|
||||
if (File.Exists(FFmpegPath))
|
||||
{
|
||||
SetupHelpers.CopyFile(FFmpegPath, destination);
|
||||
FileHelpers.CopyFiles(FFmpegPath, destination);
|
||||
}
|
||||
|
||||
FileHelpers.CopyAll(Path.Combine(ParentDir, @"ShareX.ScreenCaptureLib\Stickers"), Path.Combine(destination, "Stickers"));
|
||||
|
|
|
@ -1,80 +0,0 @@
|
|||
#region License Information (GPL v3)
|
||||
|
||||
/*
|
||||
ShareX - A program that allows you to take screenshots and share any file type
|
||||
Copyright (c) 2007-2022 ShareX Team
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#endregion License Information (GPL v3)
|
||||
|
||||
using ShareX.HelpersLib;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace ShareX.Setup
|
||||
{
|
||||
internal class SetupHelpers
|
||||
{
|
||||
public static void CopyFile(string path, string toFolder)
|
||||
{
|
||||
CopyFiles(new string[] { path }, toFolder);
|
||||
}
|
||||
|
||||
public static void CopyFiles(IEnumerable<string> files, string toFolder)
|
||||
{
|
||||
if (!Directory.Exists(toFolder))
|
||||
{
|
||||
Directory.CreateDirectory(toFolder);
|
||||
}
|
||||
|
||||
foreach (string filePath in files)
|
||||
{
|
||||
string fileName = Path.GetFileName(filePath);
|
||||
string dest = Path.Combine(toFolder, fileName);
|
||||
File.Copy(filePath, dest);
|
||||
}
|
||||
}
|
||||
|
||||
public static void CopyFiles(string directory, string searchPattern, string toFolder, string[] ignoreFiles = null)
|
||||
{
|
||||
string[] files = Directory.GetFiles(directory, searchPattern);
|
||||
|
||||
if (ignoreFiles != null)
|
||||
{
|
||||
List<string> newFiles = new List<string>();
|
||||
|
||||
foreach (string file in files)
|
||||
{
|
||||
string fileName = Path.GetFileName(file);
|
||||
|
||||
if (ignoreFiles.All(x => !fileName.Equals(x, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
newFiles.Add(file);
|
||||
}
|
||||
}
|
||||
|
||||
files = newFiles.ToArray();
|
||||
}
|
||||
|
||||
CopyFiles(files, toFolder);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -73,7 +73,6 @@
|
|||
<Compile Include="..\SharedAssemblyInfo.cs">
|
||||
<Link>Properties\SharedAssemblyInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="SetupHelpers.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
|
Loading…
Reference in a new issue