Files
BeWoPlaner/BeWoLauncher/Logic/Utils/LauncherPaths.cs
rene 4fbfdbaf2c Unit Tests erstellt
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
2022-12-28 16:36:59 +01:00

127 lines
4.0 KiB
C#

using BeWoLauncher.Logic.Controller;
using BS.SharedLauncher.Extensions;
using BS.SharedLauncher.Information;
using BS.SharedLauncher.Logic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace BeWoLauncher.Logic.Utils
{
public static class LauncherPaths
{
private static readonly string planerExeName = "BeWoPlaner.exe";
//private static readonly string versionXml = "bewo.version";
public static string LoginSelectionPlanerLocation { get; set; }
public static string ActualPlanerLocation { get; set; }
/// <summary>
/// Holt den Install Ort aus den Properties Settings.
/// Sollte dieser nicht verfügbar sein, wird als default - "CurrentBaseDir"/BeWoPlaner - verwendet
/// </summary>
/// <returns></returns>
public static string GetInstallLocationFromSettingOrDefault()
{
var installLocation = GetInstallLocationFromSetting();
if (string.IsNullOrWhiteSpace(installLocation))
{
installLocation = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, BeWoPathFileConfig.SubDirectory);
}
return installLocation;
}
public static string GetInstallLocationFromSetting()
{
return LauncherAppdataConfig.GetInstallLocation();
}
/// <summary>
///
/// </summary>
/// <param name="newLocation"></param>
/// <returns>Gibt true aus, wenn der Path sich verändert hat.</returns>
public static bool ChangePath(string newLocation)
{
var info = new DirectoryInfo(newLocation);
if (LoginSelectionPlanerLocation == newLocation)
{
return false;
}
//if (newLocation.Exists() && (info.GetDirectories().Any() || info.GetFiles().Any()))
//{
// MessageBox.Show($"Ordner muss leer sein! Es sind {info.GetDirectories().Count()} Ordner und {info.GetFiles().Count()} Datei(en) enthalten");
// return false;
//}
// Annahme: Ordner ist leer und neuer Ort
LoginSelectionPlanerLocation = newLocation;
return true;
}
public static void SetAndSaveInstallLocation(string path)
{
ActualPlanerLocation = path;
LauncherAppdataConfig.SetInstallLocation(path);
}
public static string GetRootPath()
{
return ActualPlanerLocation;
}
public static string GetLoggerPath()
{
return Path.Combine(new string[] { GetRootPath(), "log" });
}
public static string GetDownloadPath()
{
return Path.Combine(new string[] { GetRootPath(), "download" });
}
public static string GetApplyPath()
{
return Path.Combine(new string[] { GetRootPath(), "apply" });
}
public static string GetPlanerExeName() => planerExeName;
public static string GetPlanerExePath()
{
return Path.Combine(GetApplyPath(), GetPlanerExeName());
}
public static void SaveCurrentInfo(this string path, string file)
{
FileController.SaveInfo(path.Combine(file), DownloadController.Manager.UpdatePlanResponse.CurrentPackage);
}
public static void SaveFile(this string path, byte[] data)
{
FileController.SaveFile(path, data);
}
public static void CopyFileTo(this string source, string destination)
{
FileController.CopyFile(source, destination);
}
public static void DeleteFile(this string file)
{
FileController.DeleteFile(file);
}
public static void DeleteEmptyDirectories(this string dir)
{
FileController.DeleteEmptyDirectories(dir);
}
}
}