Ejemplo n.º 1
0
        public static void Upgrade(string dirToNewVersion)
        {
            var myDir = Path.GetDirectoryName(System.AppContext.BaseDirectory);

            if (Directory.Exists(dirToNewVersion))
            {
                var installFrom = dirToNewVersion;
                var argInstall  = GetInstallationStatus() == Status.Installed ? " --install" : "";

                var possibleInstallDir = Path.Combine(dirToNewVersion, "Sonic4ModLoader");
                if (Directory.Exists(possibleInstallDir))
                {
                    installFrom = possibleInstallDir;
                }

                Uninstall(new UninstallationOptions());

                foreach (var file in Directory.GetFileSystemEntries(installFrom))
                {
                    if (file.EndsWith("Sonic4ModManager.exe"))
                    {
                        continue;
                    }
                    var myFile = Path.Combine(myDir, Path.GetFileName(file));
                    if (File.Exists(file))
                    {
                        if (File.Exists(myFile))
                        {
                            File.Delete(myFile);
                        }
                        File.Move(file, myFile);
                    }
                    else
                    {
                        MyDirectory.CopyAll(file, myFile);
                        Directory.Delete(file, true);
                    }
                }

                var bat = "taskkill /IM Sonic4ModManager.exe /F\n" +
                          "MOVE /Y \"" + installFrom + "\"\\Sonic4ModManager.exe \"" + myDir + "\"\\Sonic4ModManager.exe\n" +
                          "RMDIR /Q /S \"" + dirToNewVersion + "\"\n" +
                          "START \"\" /D \"" + myDir + "\" Sonic4ModManager.exe" + argInstall + "\n" +
                          "DEL FinishUpgrade.bat";

                File.WriteAllText("FinishUpgrade.bat", bat);
                Process.Start("FinishUpgrade.bat");
                Environment.Exit(0);
            }
        }
Ejemplo n.º 2
0
        async public void FinishInstallation()
        {
            progressBar.Style = ProgressBarStyle.Marquee;
            await Task.Run(() =>
            {
                statusBar.Text = "Installing downloaded mod...";

                foreach (string mod in Installation.ModRoots)
                {
                    string dest;

                    switch (Installation.Platform)
                    {
                    case ModType.PC:      dest = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "mods", Path.GetFileName(mod)); break;

                    case ModType.Dolphin: dest = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Dolphin Emulator", "Load", "Textures"); break;

                    case ModType.Unknown: dest = Installation.CustomPath; break;

                    default:              dest = Settings.Paths[Installation.Platform.ToString()]; break;
                    }

                    if (Directory.Exists(dest) && Installation.Platform == ModType.PC)
                    {
                        MyDirectory.DeleteRecursively(dest);
                    }

                    if (Installation.Platform != ModType.Unknown)
                    {
                        MyDirectory.CopyAll(mod, dest);
                    }
                    else
                    {
                        if (File.Exists(Path.Combine(Installation.ArchiveDir, mod)))
                        {
                            File.Copy(Path.Combine(Installation.ArchiveDir, mod), Path.Combine(dest, Path.GetFileName(mod)));
                        }
                        else if (Directory.Exists(Path.Combine(Installation.ArchiveDir, mod)))
                        {
                            MyDirectory.CopyAll(Path.Combine(Installation.ArchiveDir, mod), Path.Combine(dest, Path.GetFileName(mod)));
                        }
                    }
                }

                if (!Installation.FromDir)
                {
                    MyDirectory.DeleteRecursively(Installation.ArchiveDir);
                }

                if (File.Exists(Installation.ArchiveName) && !Installation.Local)
                {
                    if (Settings.SaveDownloadedArchives)
                    {
                        Directory.CreateDirectory(Settings.Paths["DownloadedArhives"]);
                        File.Move(Installation.ArchiveName, Path.Combine(Settings.Paths["DownloadedArhives"], Installation.ArchiveName));
                    }
                    else
                    {
                        File.Delete(Installation.ArchiveName);
                    }
                }

                if (Settings.ExitLaunchManager)
                {
                    if (Installation.Platform == ModType.PC && File.Exists("Sonic4ModManager.exe"))
                    {
                        Process.Start("Sonic4ModManager.exe", "\"" + UltimateWinForm.Installation.LastMod + "\"");
                    }
                    Environment.Exit(0);
                }

                statusBar.Text      = "Mod installation complete!";
                Installation.Status = "Installed";

                tcMain.Invoke(new MethodInvoker(delegate {
                    UpdateWindow();
                }));
            });
        }