Files
BeWoPlaner/BeWoLauncher/Logic/Utils/LauncherPaths.cs
Rene Evertz 6497a7ded5 Working now
- more logs
- download controller + manager überarbeitet
- Retry wird besser angezeigt
- Formatierungen
2024-06-07 13:42:25 +02:00

127 lines
4.1 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 PlanerLocation { 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 GetPlanerLocationFromSettingOrDefault()
{
var installLocation = GetPlanerLocationFromSetting();
if (string.IsNullOrWhiteSpace(installLocation))
{
installLocation = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, BeWoPathFileConfig.SubDirectory);
}
return installLocation;
}
public static string GetPlanerLocationFromSetting()
{
return LauncherAppdataConfig.GetPlanerLocation();
}
/// <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)
{
PlanerLocation = path;
LauncherAppdataConfig.SetPlanerLocation(path);
LauncherAppdataConfig.SetInstallLocationSetSuccess(true);
}
public static string GetRootPath()
{
return PlanerLocation;
}
public static string GetLoggerPath()
{
return Path.Combine(new string[] { LauncherAppdataConfig.Folder, "log", "update" });
}
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);
}
}
}