private static void Main() { try { string lockfile = Path.Combine(Paths.GetDataPath(), "lockfile"); File.Create(lockfile).Dispose(); FileStream fs = File.Open(lockfile, FileMode.Open, FileAccess.ReadWrite, FileShare.None); } catch { MessageBox.Show("Another instance of Cupscale seems to be running, accessing the following data folder:\n" + Paths.GetDataPath() + ".\n\nMultiple instance are only possible if they use different data folders.\n" + "Starting Cupscale with \"-portable\" will use the current directory as data folder.", "Error"); return; } Application.SetCompatibleTextRenderingDefault(defaultValue: false); Application.EnableVisualStyles(); IOUtils.DeleteIfExists(Path.Combine(Paths.GetDataPath(), "sessionlog.txt")); Config.Init(); Logger.Init(); Paths.Init(); ResourceLimits.Memory = (ulong)Math.Round(ResourceLimits.Memory * 1.5f); Cleanup(); Application.Run(new MainForm()); }
static async Task DownloadAndInstall(int version, string filename, bool showDialog = true) { string savePath = Path.Combine(Paths.GetDataPath(), filename); string url = $"https://dl.nmkd.de/cupscale/shippedfiles/{version}/{filename}"; Logger.Log($"[Installer] Downloading {url}"); var client = new WebClient(); currentDlDialog = new DialogForm($"Downloading {filename}…"); sw.Restart(); client.DownloadProgressChanged += DownloadProgressChanged; await client.DownloadFileTaskAsync(new Uri(url), savePath); if (Path.GetExtension(filename).ToLower() == ".7z") // Only run extractor if it's a 7z archive { if (currentDlDialog != null) { currentDlDialog.ChangeText($"Installing {filename}..."); } await UnSevenzip(Path.Combine(Paths.GetDataPath(), filename)); } if (currentDlDialog != null) { currentDlDialog.Close(); } currentDlDialog = null; }
static async Task UnSevenzip(string path) { Logger.Log("[Installer] Extracting " + path); await Task.Delay(20); SevenZipNET.SevenZipExtractor.Path7za = path7za; SevenZipNET.SevenZipExtractor extractor = new SevenZipNET.SevenZipExtractor(path); extractor.ExtractAll(Paths.GetDataPath(), true, true); File.Delete(path); await Task.Delay(10); }
public static bool InstallationIsValid() { List <string> requiredDirs = new List <string>(); requiredDirs.Add(Path.Combine(path, "Tools")); requiredDirs.Add(Path.Combine(path, "Tools", "Lib", "site-packages")); requiredDirs.Add(Path.Combine(path, "utils")); List <string> requiredFiles = new List <string>(); requiredFiles.Add(Path.Combine(Paths.GetDataPath(), "shipped-files-version.txt")); requiredFiles.Add(Path.Combine(path, "upscale.py")); requiredFiles.Add(Path.Combine(path, "ffmpeg.exe")); requiredFiles.Add(Path.Combine(path, "esrgan-ncnn-vulkan.exe")); requiredFiles.Add(Path.Combine(path, "pth2ncnn.exe")); requiredFiles.Add(Path.Combine(path, "nvcompress.exe")); requiredFiles.Add(Path.Combine(path, "nvtt.dll")); requiredFiles.Add(Path.Combine(path, "gifski.exe")); foreach (string dir in requiredDirs) { if (!Directory.Exists(dir)) { Logger.Log("[Installer] Installation invalid: Directory " + dir + " not found"); return(false); } } foreach (string file in requiredFiles) { if (!File.Exists(file)) { Logger.Log("[Installer] Installation invalid: File " + file + " not found"); return(false); } } int diskVersion = IOUtils.ReadLines(Path.Combine(Paths.GetDataPath(), "shipped-files-version.txt"))[0].Split('#')[0].GetInt(); if (exeFilesVersion != diskVersion) { Logger.Log("[Installer] Installation invalid: Shipped file version mismatch - Executable is " + exeFilesVersion + ", installation is " + diskVersion); return(false); } return(true); }
public static void Cleanup() { try { IOUtils.ClearDir(Paths.previewPath); IOUtils.ClearDir(Paths.previewOutPath); IOUtils.ClearDir(Paths.clipboardFolderPath); IOUtils.ClearDir(Paths.imgInPath); IOUtils.ClearDir(Paths.imgOutPath); IOUtils.ClearDir(Paths.imgOutNcnnPath); IOUtils.ClearDir(Paths.tempImgPath.GetParentDir()); IOUtils.ClearDir(Path.Combine(Paths.GetDataPath(), "giftemp")); IOUtils.DeleteIfExists(Path.Combine(Paths.presetsPath, "lastUsed")); IOUtils.ClearDir(Paths.compositionOut); IOUtils.ClearDir(Paths.framesOutPath); IOUtils.DeleteIfExists(Path.Combine(Paths.GetDataPath(), "frames-out.mp4")); } catch (Exception e) { Logger.Log("Error during cleanup: " + e.Message); } }
public static void Uninstall(bool full) { if (!Directory.Exists(Paths.GetDataPath())) { return; } try { if (full) { Directory.Delete(Paths.GetDataPath(), true); } else { Directory.Delete(path, true); } } catch (Exception e) { Logger.Log("Failed to uninstall.\nClose Cupscale and try deleting CupscaleData manually. " + e.Message); } }