Files
BeWoPlaner/BeWoLauncher/UpdatePathManager.cs

93 lines
3.1 KiB
C#

using BeWoLauncher.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace BeWoLauncher
{
public static class UpdatePathManager
{
public static string LoginUpdateLocation { get; set; }
public static string UpdateLocation { get; private set; }
public static DirectoryInfo UpdateDirectoryInfo { get; private 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 = Properties.Settings.Default.InstallLocation;
if (string.IsNullOrWhiteSpace(installLocation))
{
installLocation = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, GetMainExeName());
}
return installLocation;
}
/// <summary>
/// Speichert den aktuellen Update Path
/// </summary>
public static void SaveInstallLocation()
{
Properties.Settings.Default.InstallLocation = UpdateLocation;
Properties.Settings.Default.Save();
}
public static void ChangeLoginSelectedLocation(string newLocation)
{
var info = new DirectoryInfo(newLocation);
if (LoginUpdateLocation == newLocation)
{
return;
}
if (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;
}
// Annahme: Ordner ist leer und neuer Ort
LoginUpdateLocation.ClearFolder();
LoginUpdateLocation = newLocation;
}
public static void SetUpdatePath(string path)
{
UpdateLocation = path;
UpdateDirectoryInfo = new DirectoryInfo(path);
// GetDownloadDirInfo();
// GetApplyDirInfo();
}
// No cache
public static string GetDownloadPath()
{
return Path.Combine(new string[] { UpdateLocation, "download" });
}
public static DirectoryInfo GetDownloadDirInfo()
{
return Directory.CreateDirectory(GetDownloadPath());
}
public static string GetApplyPath()
{
return Path.Combine(new string[] { UpdateLocation, "local", "BeWoPlaner" });
}
public static DirectoryInfo GetApplyDirInfo()
{
return Directory.CreateDirectory(GetApplyPath());
}
public static string GetMainExeName() => "BeWoPlaner.exe";
public static string GetPlanerPath()
{
return Path.Combine(GetApplyPath(), GetMainExeName());
}
}
}