mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-27 07:04:57 +01:00
TGS3 (#3)
Let's just get this merged instead of having a massive PR Original PR: tgstation/tgstation#26534
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace TGServerService
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
static void Main() => new TGServerService(); //wondows
|
||||
|
||||
//Everything in this file is just generic helpers
|
||||
|
||||
//http://stackoverflow.com/questions/1701457/directory-delete-doesnt-work-access-denied-error-but-under-windows-explorer-it
|
||||
public static void DeleteDirectory(string path, bool ContentsOnly = false)
|
||||
{
|
||||
var di = new DirectoryInfo(path);
|
||||
if (!di.Exists)
|
||||
return;
|
||||
NormalizeAndDelete(di);
|
||||
if(!ContentsOnly)
|
||||
di.Delete(true);
|
||||
}
|
||||
static void NormalizeAndDelete(DirectoryInfo dir)
|
||||
{
|
||||
foreach (var subDir in dir.GetDirectories())
|
||||
{
|
||||
NormalizeAndDelete(subDir);
|
||||
subDir.Delete(true);
|
||||
}
|
||||
foreach (var file in dir.GetFiles())
|
||||
{
|
||||
file.Attributes = FileAttributes.Normal;
|
||||
}
|
||||
}
|
||||
|
||||
public static void CopyDirectory(string sourceDirName, string destDirName, IList<string> ignore = null, bool ignoreIfNotExists = false)
|
||||
{
|
||||
// If the destination directory doesn't exist, create it.
|
||||
if (!Directory.Exists(destDirName))
|
||||
{
|
||||
Directory.CreateDirectory(destDirName);
|
||||
}
|
||||
// Get the subdirectories for the specified directory.
|
||||
DirectoryInfo dir = new DirectoryInfo(sourceDirName);
|
||||
|
||||
if (!dir.Exists)
|
||||
{
|
||||
if (ignoreIfNotExists)
|
||||
return;
|
||||
throw new DirectoryNotFoundException(
|
||||
"Source directory does not exist or could not be found: "
|
||||
+ sourceDirName);
|
||||
}
|
||||
|
||||
DirectoryInfo[] dirs = dir.GetDirectories();
|
||||
|
||||
// Get the files in the directory and copy them to the new location.
|
||||
FileInfo[] files = dir.GetFiles();
|
||||
foreach (FileInfo file in files)
|
||||
{
|
||||
if (ignore != null && ignore.Contains(file.Name))
|
||||
continue;
|
||||
string temppath = Path.Combine(destDirName, file.Name);
|
||||
file.CopyTo(temppath, true);
|
||||
}
|
||||
|
||||
// copy them and their contents to new location.
|
||||
foreach (DirectoryInfo subdir in dirs)
|
||||
{
|
||||
if (ignore != null && ignore.Contains(subdir.Name))
|
||||
continue;
|
||||
string temppath = Path.Combine(destDirName, subdir.Name);
|
||||
CopyDirectory(subdir.FullName, temppath, ignore);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user