Informationen ausgelagert Kleines Spy/Test Programm erstellt Mehr Exceptions/InvalidUpdateFileRequestException.cs Launcher Host in Download Server geändert Download Server macht zusätzlich Abfrage an den Hauptserver Download geht jetzt stückweise von statten
86 lines
2.3 KiB
C#
86 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using BS.SharedLauncher.Information;
|
|
using BS.SharedLauncher.Logic;
|
|
|
|
namespace BS.SharedLauncher.Extensions
|
|
{
|
|
public static class PathExtensions
|
|
{
|
|
public static string Combine(this string start, string sub)
|
|
{
|
|
return Path.Combine(start, sub);
|
|
}
|
|
public static void CreateFolder(this string path)
|
|
{
|
|
Directory.CreateDirectory(path);
|
|
}
|
|
public static bool Exists(this string path)
|
|
{
|
|
try
|
|
{
|
|
FileAttributes attr = File.GetAttributes(path);
|
|
|
|
if (attr.HasFlag(FileAttributes.Directory))
|
|
{
|
|
return Directory.Exists(path);
|
|
}
|
|
return File.Exists(path);
|
|
}
|
|
catch (FileNotFoundException)
|
|
{
|
|
|
|
}
|
|
catch (DirectoryNotFoundException)
|
|
{
|
|
|
|
}
|
|
catch (Exception)
|
|
{
|
|
|
|
}
|
|
return false;
|
|
}
|
|
public static bool IsFolderEmpty(this string path)
|
|
{
|
|
return !Directory.EnumerateFileSystemEntries(path).Any();
|
|
}
|
|
|
|
public static void ClearFolder(this string path) => ClearFolder(new DirectoryInfo(path));
|
|
public static void ClearFolder(this DirectoryInfo di)
|
|
{
|
|
foreach (FileInfo file in di.EnumerateFiles())
|
|
{
|
|
file.Delete();
|
|
}
|
|
foreach (DirectoryInfo dir in di.EnumerateDirectories())
|
|
{
|
|
dir.Delete(true);
|
|
}
|
|
}
|
|
|
|
public static void Lock(this string path, bool skiplock)
|
|
{
|
|
var file = Path.Combine(path, BeWoPathFileConfig.LockFileName);
|
|
|
|
if (!skiplock && File.Exists(file))
|
|
throw new ArgumentException($"Lock ist bereits gesetzt", path);
|
|
|
|
using (File.Create(file));
|
|
}
|
|
public static void Unlock(this string path)
|
|
{
|
|
var file = Path.Combine(path, BeWoPathFileConfig.LockFileName);
|
|
|
|
if (!File.Exists(file))
|
|
throw new ArgumentException($"Unlock nicht möglich, Lock existiert nicht", path);
|
|
|
|
File.Delete(file);
|
|
}
|
|
}
|
|
}
|