Esempio n. 1
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();
                }));
            });
        }
Esempio n. 2
0
        async public void DoTheRest()
        {
            tcMain.Invoke(new MethodInvoker(delegate
            {
                progressBar.Style = ProgressBarStyle.Marquee;
                progressBar.Value = 0;
            }));

            await Task.Run(() =>
            {
                if (!Installation.FromDir)
                {
                    statusBar.Text = "Extracting downloaded archive...";

                    Installation.ArchiveDir = Installation.ArchiveName + "_extracted";

                    if (File.Exists(Installation.ArchiveName))
                    {
                        if (Directory.Exists(Installation.ArchiveName + "_extracted"))
                        {
                            MyDirectory.DeleteRecursively(Installation.ArchiveName + "_extracted");
                        }

                        if (Settings.UseLocal7zip)
                        {
                            ModArchive.Extract(Installation.ArchiveName, Settings.Paths["7-Zip"]);
                        }
                        else
                        {
                            ModArchive.Extract(Installation.ArchiveName);
                        }
                    }
                }

                if (File.Exists(Installation.ArchiveDir))
                {
                    statusBar.Text      = "Couldn't extract archive";
                    Installation.Status = "Idle";
                }

                var cont = -1;

                if (!Directory.Exists(Installation.ArchiveDir))
                {
                    statusBar.Text      = "Couldn't extract archive";
                    Installation.Status = "Idle";
                    if (!(File.Exists("7z.exe") || (File.Exists(Settings.Paths["7-Zip"]) && Settings.UseLocal7zip)))
                    {
                        statusBar.Text += " (7-Zip not found)";
                    }
                }
                else
                {
                    statusBar.Text = "Checking extracted files...";
                    cont           = ModArchive.CheckFiles(Installation.ArchiveDir);
                }

                if (cont == 0)
                {
                    MyDirectory.DeleteRecursively(Installation.ArchiveDir);
                    statusBar.Text      = "Installation was cancelled";
                    Installation.Status = "Cancelled";
                }
                else if (cont == 1)
                {
                    statusBar.Text = "Finding root directories...";

                    var FoundRootDirs = ModArchive.FindRoot(Installation.ArchiveDir);

                    if (FoundRootDirs.Item2 != ModType.Unknown)
                    {
                        Installation.ModRoots = FoundRootDirs.Item1;
                        Installation.Platform = FoundRootDirs.Item2;
                    }

                    Installation.Status = "Ready to install";

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