Exemple #1
0
        public static async Task Install()
        {
            Program.mainForm.Enabled = false;
            DialogForm dialog = new DialogForm("Installing resources...\nThis only needs to be done once.");
            await Task.Delay(20);

            Directory.CreateDirectory(path);

            path7za = Path.Combine(path, "7za.exe");
            File.WriteAllBytes(path7za, Resources.x64_7za);
            File.WriteAllBytes(Path.Combine(IOUtils.GetAppDataDir(), "esrgan.7z"), Resources.esrgan);
            File.WriteAllBytes(Path.Combine(IOUtils.GetAppDataDir(), "ncnn.7z"), Resources.esrgan_ncnn);
            File.WriteAllBytes(Path.Combine(IOUtils.GetAppDataDir(), "av.7z"), Resources.av);

            dialog.ChangeText("Installing ESRGAN resources...");
            await UnSevenzip(Path.Combine(IOUtils.GetAppDataDir(), "esrgan.7z"));

            dialog.ChangeText("Installing ESRGAN-NCNN-Vulkan resources...");
            await UnSevenzip(Path.Combine(IOUtils.GetAppDataDir(), "ncnn.7z"));

            dialog.ChangeText("Installing Audio/Video/Image resources...");
            await UnSevenzip(Path.Combine(IOUtils.GetAppDataDir(), "av.7z"));

            File.WriteAllText(Path.Combine(IOUtils.GetAppDataDir(), "shipped_files_version"), Resources.shipped_files_version);

            dialog.Close();
            Program.mainForm.Enabled     = true;
            Program.mainForm.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            Program.mainForm.BringToFront();
        }
Exemple #2
0
        static async Task DownloadAndInstall(int version, string filename, bool showDialog = true)
        {
            string savePath = Path.Combine(IOUtils.GetAppDataDir(), 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(IOUtils.GetAppDataDir(), filename));
            }
            if (currentDlDialog != null)
            {
                currentDlDialog.Close();
            }
            currentDlDialog = null;
        }
Exemple #3
0
 static void DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
 {
     if (sw.ElapsedMilliseconds > 250)
     {
         sw.Restart();
         string newText = currentDlDialog.GetText().Split('…')[0] + "… " + e.ProgressPercentage + "%";
         currentDlDialog.ChangeText(newText);
     }
 }
Exemple #4
0
        public static async Task Install()
        {
            Program.mainForm.Enabled = false;
            DialogForm dialog = new DialogForm("Installing resources...\nThis only needs to be done once.");
            await Task.Delay(20);

            if (IOUtils.GetDirSize(path) > 0)
            {
                Logger.Log("[Installer] {path} is not 0 bytes - removing everything there to ensure a clean install.");
                dialog.ChangeText("Uninstalling older files...");
                await Task.Delay(20);

                Uninstall(false);
            }

            Directory.CreateDirectory(path);

            path7za = Path.Combine(path, "7za.exe");
            File.WriteAllBytes(path7za, Resources.x64_7za);

            try
            {
                await DownloadAndInstall(exeFilesVersion, "esrgan.7z");
                await DownloadAndInstall(exeFilesVersion, "esrgan-ncnn.7z");
                await DownloadAndInstall(exeFilesVersion, "av.7z");
                await DownloadAndInstall(exeFilesVersion, "shipped-files-version.txt", false);
            }
            catch (Exception e)
            {
                MsgBox msg = Logger.ErrorMessage("Web Installer failed to run!\n", e);
                while (DialogQueue.IsOpen(msg))
                {
                    await Task.Delay(50);
                }
                Environment.Exit(1);
                return;
            }

            dialog.Close();
            Program.mainForm.Enabled     = true;
            Program.mainForm.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            Program.mainForm.BringToFront();
        }