You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.8 KiB
52 lines
1.8 KiB
1 year ago
|
using System.Reflection;
|
||
1 year ago
|
|
||
1 year ago
|
namespace StabilityMatrix.Core.Helper;
|
||
1 year ago
|
|
||
|
public static class Utilities
|
||
|
{
|
||
|
public static string GetAppVersion()
|
||
|
{
|
||
|
var assembly = Assembly.GetExecutingAssembly();
|
||
|
var version = assembly.GetName().Version;
|
||
|
return version == null
|
||
|
? "(Unknown)"
|
||
|
: $"{version.Major}.{version.Minor}.{version.Build}.{version.Revision}";
|
||
|
}
|
||
1 year ago
|
|
||
|
public static void CopyDirectory(string sourceDir, string destinationDir, bool recursive,
|
||
|
bool includeReparsePoints = false)
|
||
|
{
|
||
|
// Get information about the source directory
|
||
|
var dir = new DirectoryInfo(sourceDir);
|
||
|
|
||
|
// Check if the source directory exists
|
||
|
if (!dir.Exists)
|
||
|
throw new DirectoryNotFoundException($"Source directory not found: {dir.FullName}");
|
||
|
|
||
|
// Cache directories before we start copying
|
||
|
var dirs = includeReparsePoints
|
||
|
? dir.GetDirectories()
|
||
|
: dir.GetDirectories().Where(d => !d.Attributes.HasFlag(FileAttributes.ReparsePoint));
|
||
|
|
||
|
// Create the destination directory
|
||
|
Directory.CreateDirectory(destinationDir);
|
||
|
|
||
|
// Get the files in the source directory and copy to the destination directory
|
||
|
foreach (var file in dir.GetFiles())
|
||
|
{
|
||
|
var targetFilePath = Path.Combine(destinationDir, file.Name);
|
||
1 year ago
|
if (file.FullName == targetFilePath) continue;
|
||
|
file.CopyTo(targetFilePath, true);
|
||
1 year ago
|
}
|
||
|
|
||
|
if (!recursive) return;
|
||
|
|
||
|
// If recursive and copying subdirectories, recursively call this method
|
||
|
foreach (var subDir in dirs)
|
||
|
{
|
||
|
var newDestinationDir = Path.Combine(destinationDir, subDir.Name);
|
||
|
CopyDirectory(subDir.FullName, newDestinationDir, true);
|
||
|
}
|
||
|
}
|
||
1 year ago
|
}
|