Ejemplo n.º 1
0
        protected override async void OnClick(EventArgs e)
        {
            // start by clearing all of the controls in the ociform and stopping the audio
            OCIForm.instance.Controls.Clear();
            Audio.Stop();

            // then initialize the loading bar, show the extracting message and play the loading bgm
            LoadingBar loadingBar = new LoadingBar(OCIForm.instance);

            loadingBar.SetLoadingStatus(string.Format("Extracting {0}, please wait...", OCIForm.instance.modPath.Name));
            Audio.PlaySound(loadingBar.GetLoadingBGM(), false);

            // extract the zip archive
            try
            {
                string zipDestination = Static.modsPath + OCIForm.instance.modPath.Name;

                if (!Directory.Exists(zipDestination))
                {
                    await Task.Run(() =>
                    {
                        ZipFile.ExtractToDirectory(OCIForm.instance.modPath.FullName, zipDestination);
                    });
                }
            }
            catch (Exception ex)
            {
                string message = "An exception was encountered:\n---------------\n"
                                 + ex.Message + "\n---------------\n" + ex.ToString();

                MessageBox.Show(message);
            }

            // then if we've been told by the checkboxes to directly apply the zip archive to oneshot, install the mod
            if (OCIDirectApply.instance.Checked)
            {
                ChangesManage.MultithreadStuff(true, loadingBar, new DirectoryInfo(Static.modsPath + OCIForm.instance.modPath.Name), OCIDeleteExisting.instance.Checked);
            }
        }
Ejemplo n.º 2
0
        protected override async void OnClick(EventArgs e)
        {
            DevToolsForm.instance.Controls.Clear();

            using (FolderBrowserDialog browse = new FolderBrowserDialog())
            {
                browse.Description = "Please navigate to your mod's path.";
                browse.ShowDialog();

                if (browse.SelectedPath != string.Empty)
                {
                    try
                    {
                        LoadingBar loadingBar = new LoadingBar(DevToolsForm.instance);
                        Audio.PlaySound(loadingBar.GetLoadingBGM(), false);
                        loadingBar.SetLoadingStatus("Please wait a moment...");

                        await Task.Run(() =>
                        {
                            ZipFile.CreateFromDirectory(browse.SelectedPath, browse.SelectedPath + ".osml");
                        });

                        Console.Beep();
                        MessageBox.Show("All done!");

                        loadingBar.text.Dispose();
                        Audio.Stop();
                    }
                    catch (Exception ex)
                    {
                        ExceptionMessage.New(ex, true);
                    }
                }
            }

            DevToolsForm.instance.Init();
        }
Ejemplo n.º 3
0
        private static void DoStuff(object sender, DoWorkEventArgs e)
        {
            SetupArgs?booga = e.Argument as SetupArgs?;

            if (booga is null)
            {
                throw new Exception("absolutely no idea how you did that but good work");
            }

            string     path       = booga.Value.path;
            LoadingBar loadingBar = booga.Value.loadingBar;

            Audio.PlaySound(loadingBar.GetLoadingBGM(), true);

            if (!Verify(path)) // verify the installation
            {
                MessageBox.Show("Could not find a valid OneShot installation at that location. Please double-check for typos in your path.");
                Audio.Stop();
                loadingBar.ReportProgress(sender, new ProgressChangedEventArgs(0, LoadingBar.ProgressType.ReturnToMenu));
                return;
            }

            try
            {
                Logger.WriteLine("setup begin");

                loadingBar.ReportProgress(sender, new ProgressChangedEventArgs(0, "working, please wait a moment"));

                // get directories and files from base os
                DirectoryInfo   baseOs      = new DirectoryInfo(path);
                DirectoryInfo[] directories = baseOs.GetDirectories("*", SearchOption.AllDirectories);
                FileInfo[]      files       = baseOs.GetFiles("*", SearchOption.AllDirectories);

                // set the maximum of the loading bar to the length of the directories and files
                loadingBar.ReportProgress(sender, new ProgressChangedEventArgs
                                              (directories.Length + files.Length, LoadingBar.ProgressType.SetMaximumProgress));

                // create directories
                loadingBar.ReportProgress(sender, new ProgressChangedEventArgs(0, "setting up directories"));
                foreach (DirectoryInfo d in directories)
                {
                    string create = d.FullName.Replace(path, string.Empty); // create the name of the directory to create

                    // and create it
                    if (!Directory.Exists(Static.modsPath + "/base oneshot/" + create))
                    {
                        Directory.CreateDirectory(Static.modsPath + "/base oneshot/" + create);
                    }

                    // update loading bar
                    if (loadingBar.displayType == LoadingBar.LoadingBarType.Detailed)
                    {
                        loadingBar.ReportProgress(sender, new ProgressChangedEventArgs(0, $"setup: {d.FullName}"));
                    }
                    loadingBar.ReportProgress(sender, new ProgressChangedEventArgs(1, LoadingBar.ProgressType.UpdateProgress));

                    //loadingBar.UpdateProgress();
                }

                loadingBar.ReportProgress(sender, new ProgressChangedEventArgs(0, LoadingBar.ProgressType.ResetProgress));

                // copy files
                loadingBar.ReportProgress(sender, new ProgressChangedEventArgs(0, "setting up files"));
                foreach (FileInfo f in files)
                {
                    string copyPath = f.FullName.Replace(path, string.Empty); // create the name of the file to create

                    // and copy it
                    if (!File.Exists(Static.modsPath + "/base oneshot/" + copyPath))
                    {
                        f.CopyTo(Static.modsPath + "/base oneshot/" + copyPath, true); // overwrite
                    }
                    if (loadingBar.displayType == LoadingBar.LoadingBarType.Detailed)
                    {
                        loadingBar.ReportProgress(sender, new ProgressChangedEventArgs(0, $"setup: {f.FullName}"));
                    }
                    loadingBar.ReportProgress(sender, new ProgressChangedEventArgs(1, LoadingBar.ProgressType.UpdateProgress));

                    //loadingBar.UpdateProgress();
                }

                #region ---------------OLD---------------

                /*
                 * // first we need to copy all of the directories
                 * string[] dirs = Directory.GetDirectories(path, "*", SearchOption.AllDirectories);
                 *
                 * Logger.WriteLine("dirs.Length {0}", dirs.Length);
                 *
                 * string shortDirCut = path; // shorten the directories ready to be cloned
                 * string[] shortDirs = dirs;
                 * for (int i = 0; i < shortDirs.Length; i++)
                 *  shortDirs[i] = shortDirs[i].Replace(shortDirCut, "");
                 *
                 * // create the new directory
                 * foreach (string s in shortDirs)
                 * {
                 *  await loadingBar.SetLoadingStatus("setup: " + s);
                 *
                 *  if (!Directory.Exists(Constants.modsPath + s))
                 *      Directory.CreateDirectory(Constants.modsPath + "base oneshot/" + s);
                 * }
                 *
                 * // finally, copy the files to the new location
                 * string[] files = Directory.GetFiles(path, "*", SearchOption.AllDirectories);
                 * string finalPath = Constants.modsPath + "base oneshot";
                 *
                 * Logger.WriteLine("files.Length {0}", files.Length);
                 * for (int i = 0; i < files.Length; i++)
                 * {
                 *  string fileName = files[i].Replace(path, "");
                 *  File.Copy(files[i], finalPath + fileName, true);
                 *
                 *  await loadingBar.SetLoadingStatus("setup: " + fileName);
                 * }
                 */
                #endregion

                loadingBar.ReportProgress(sender, new ProgressChangedEventArgs(0, "almost done"));

                if (File.Exists(Static.appDataPath + "path.molly"))
                {
                    File.Delete(Static.appDataPath + "path.molly");
                }
                File.WriteAllText(Static.appDataPath + "path.molly", path);

                Console.Beep();
                MessageBox.Show("All done!");

                Audio.Stop();

                Program.doneSetup = true;

                // return to menu
                loadingBar.ReportProgress(sender, new ProgressChangedEventArgs(0, LoadingBar.ProgressType.ReturnToMenu));

                // dispose loading bar
                loadingBar.ReportProgress(sender, new ProgressChangedEventArgs(0, LoadingBar.ProgressType.Dispose));
            }
            catch (Exception ex)
            {
                string message = "An exception was encountered:\n" +
                                 ex.Message + "\n------------------\n" + ex.ToString() + "\nOneShot ModLoader will now close.";

                MessageBox.Show(message);
                loadingBar.ReportProgress(sender, new ProgressChangedEventArgs(0, LoadingBar.ProgressType.Forcequit));
            }
        }
Ejemplo n.º 4
0
        /// ===================================================================
        ///                         Apply Changes
        /// ===================================================================
        public static async void Apply(object sender, DoWorkEventArgs e)
        {
            // get the parameter from the event args
            ApplyArgs?bogus = e.Argument as ApplyArgs?;

            if (bogus is null)
            {
                throw new Exception("absolutely no idea how you did that but good work");
            }

            // set field stuff
            BackgroundWorker backgroundWorker = bogus.Value.backgroundWorker; // provide this as an argument into DirectApplyArgs
            LoadingBar       loadingBar       = bogus.Value.loadingBar;       // self explanatory i guess

            // start bgm
            Audio.PlaySound(loadingBar.GetLoadingBGM(), true);

            // if there is just one mod queued, wrap to DirectApply and return
            if (ActiveMods.instance.Nodes.Count == 1)
            {
                Logger.WriteLine("ActiveMods tree only has 1 mod, switching to DirectApply instead");

                MultithreadStuff(true, loadingBar, new DirectoryInfo(Static.modsPath + ActiveMods.instance.Nodes[0].Text));
                return;
            }

            Logger.WriteLine("applying changes");
            await Task.Delay(1);

            List <string> activeMods = new List <string>();

            try
            {
                // using a string as the progress parameter sets the loading status
                loadingBar.ReportProgress(sender, new ProgressChangedEventArgs(0, "creating temp directory"));

                DirectoryInfo tempDir = new DirectoryInfo(Static.GetOrCreateTempDirectory().FullName + "\\MODCOPY\\");
                DirectoryInfo baseOs  = new DirectoryInfo(Static.baseOneShotPath);

                // create the temp directory
                if (tempDir.Exists)
                {
                    tempDir.Delete(true);                 // just in case it crashed previously
                }
                if (!Directory.Exists(tempDir.FullName))
                {
                    Directory.CreateDirectory(tempDir.FullName);
                }

                // delete the base os path
                if (baseOs.Exists)
                {
                    baseOs.Delete(true);
                }

                // now we do the cool stuff
                foreach (TreeNode t in ActiveMods.instance.Nodes)
                {
                    loadingBar.ReportProgress(sender, new ProgressChangedEventArgs(0, $"mod {t.Index + 1} out of {ActiveMods.instance.Nodes.Count}: {t.Text}"));
                    loadingBar.ReportProgress(sender, new ProgressChangedEventArgs(0, LoadingBar.ProgressType.ResetProgress));

                    activeMods.Add(t.Text);

                    DirectoryInfo mod = new DirectoryInfo(Static.directory + "Mods\\" + t.Text);

                    // get the files and directories from the mod
                    DirectoryInfo[] directories = mod.GetDirectories("*", SearchOption.AllDirectories);
                    FileInfo[]      files       = mod.GetFiles("*", SearchOption.AllDirectories);

                    // set the maximum value of the progress bar to the sum of the directories/files
                    loadingBar.ReportProgress(sender, new ProgressChangedEventArgs(directories.Length + files.Length, LoadingBar.ProgressType.SetMaximumProgress));

                    Logger.WriteLine($"mod {t.Index + 1} out of {ActiveMods.instance.Nodes.Count}: {mod.FullName}");

                    foreach (DirectoryInfo d in directories)
                    {
                        string shorten = Static.directory + "Mods\\" + t.Text + "\\";
                        string create  = tempDir.FullName + d.FullName.Replace(shorten, string.Empty); // the full name of the directory to create

                        if (!Directory.Exists(create))
                        {
                            Logger.WriteLine("creating directory: " + create);
                            Directory.CreateDirectory(create);

                            // update progress
                            loadingBar.ReportProgress(sender, new ProgressChangedEventArgs(1, LoadingBar.ProgressType.UpdateProgress));
                            if (loadingBar.displayType == LoadingBar.LoadingBarType.Detailed)
                            {
                                loadingBar.ReportProgress(sender, new ProgressChangedEventArgs(1, $"mod {t.Index + 1} out of {ActiveMods.instance.Nodes.Count}: {create}"));
                            }
                        }
                    }

                    foreach (FileInfo f in files)
                    {
                        string shorten     = Static.directory + "Mods\\" + t.Text + "\\";
                        string destination = tempDir.FullName + f.FullName.Replace(shorten, string.Empty);

                        if (!File.Exists(destination))
                        {
                            Logger.WriteLine($"copying {f.FullName} to {destination}");
                            f.CopyTo(destination, true);

                            // update progress
                            loadingBar.ReportProgress(sender, new ProgressChangedEventArgs(1, LoadingBar.ProgressType.UpdateProgress));
                            if (loadingBar.displayType == LoadingBar.LoadingBarType.Detailed)
                            {
                                loadingBar.ReportProgress(sender, new ProgressChangedEventArgs(0, $"mod {t.Index + 1} out of {ActiveMods.instance.Nodes.Count}: {f.FullName}"));
                            }
                        }
                    }
                }
                Logger.WriteLine("finished up in temp");

                loadingBar.ReportProgress(sender, new ProgressChangedEventArgs(0, "finalizing, please wait"));
                loadingBar.ReportProgress(sender, new ProgressChangedEventArgs(0, LoadingBar.ProgressType.ResetProgress));

                // now we copy everything in temp to the oneshot path

                // get the directories and files
                DirectoryInfo[] directories2 = tempDir.GetDirectories("*", SearchOption.AllDirectories);
                FileInfo[]      files2       = tempDir.GetFiles("*", SearchOption.AllDirectories);

                // set the maximum value of the progress bar to the sum of the directories and files
                loadingBar.ReportProgress(sender, new ProgressChangedEventArgs(directories2.Length + files2.Length, LoadingBar.ProgressType.SetMaximumProgress));

                foreach (DirectoryInfo d in directories2)
                {
                    string shorten = Static.directory + "temp DO NOT OPEN\\MODCOPY\\";
                    string create  = baseOs.FullName + "\\" + d.FullName.Replace(shorten, string.Empty);

                    if (!Directory.Exists(create))
                    {
                        Logger.WriteLine("creating directory: " + create);
                        Directory.CreateDirectory(create);

                        // update progress
                        loadingBar.ReportProgress(sender, new ProgressChangedEventArgs(1, LoadingBar.ProgressType.UpdateProgress));
                        if (loadingBar.displayType == LoadingBar.LoadingBarType.Detailed)
                        {
                            loadingBar.ReportProgress(sender, new ProgressChangedEventArgs(0, "final: " + create));
                        }
                    }
                }

                // and then finally, the files
                foreach (FileInfo f in files2)
                {
                    string shorten     = Static.directory + "temp DO NOT OPEN\\MODCOPY";
                    string destination = baseOs.FullName + f.FullName.Replace(shorten, string.Empty);

                    if (!File.Exists(destination))
                    {
                        Logger.WriteLine($"copying {f.FullName} to {destination}");
                        f.CopyTo(destination, true);

                        // update progress
                        loadingBar.ReportProgress(sender, new ProgressChangedEventArgs(1, LoadingBar.ProgressType.UpdateProgress));
                        if (loadingBar.displayType == LoadingBar.LoadingBarType.Detailed)
                        {
                            loadingBar.ReportProgress(sender, new ProgressChangedEventArgs(0, "final: " + destination));
                        }
                    }
                }

                // done!
                loadingBar.ReportProgress(sender, new ProgressChangedEventArgs(0, "almost done!"));

                Logger.WriteLine("finished copying files");

                Static.GetOrCreateTempDirectory().Delete(true);
                Logger.WriteLine("successfully deleted temp");

                Logger.WriteLine("activeMods.Count " + activeMods.Count);
                // write the active mods to a file
                if (File.Exists(Static.appDataPath + "activemods.molly"))
                {
                    File.Delete(Static.appDataPath + "activemods.molly");
                }
                File.WriteAllLines(Static.appDataPath + "activemods.molly", activeMods);

                Console.Beep();

                /*
                 * DialogResult dr = MessageBox.Show("All done! Would you like to launch OneShot?", string.Empty, MessageBoxButtons.YesNo);
                 * if (dr == DialogResult.Yes)
                 *  Static.LaunchOneShot();*/
                MessageBox.Show("All done!");

                loadingBar.ReportProgress(sender, new ProgressChangedEventArgs(0, LoadingBar.ProgressType.Dispose));

                Logger.WriteLine("finished applying changes");

                Audio.Stop();

                MainForm.instance.Invoke(new Action(() => { MainForm.instance.ClearControls(true); }));
                MainForm.instance.Invoke(new Action(() => { MainForm.instance.InitStartMenu(); }));
            }
            catch (Exception ex)
            {
                ExceptionMessage.New(ex, true, "OneShot ModLoader will now close.");
                loadingBar.ReportProgress(sender, new ProgressChangedEventArgs(0, LoadingBar.ProgressType.Forcequit));
            }
        }
Ejemplo n.º 5
0
        protected override void OnClick(EventArgs e)
        {
            try
            {
                MMDForm.instance.Controls.Clear();

                DirectoryInfo path = new DirectoryInfo(MMDForm.modPath + "\\.osml");
                if (!path.Exists)
                {
                    path.Create();               // TODO: mark this as hidden
                }
                LoadingBar loadingBar = new LoadingBar(MMDForm.instance);
                loadingBar.SetLoadingStatus("working, please wait...");
                Audio.PlaySound(loadingBar.GetLoadingBGM(), false);

                // values
                string displayName = MMDForm.displayNameInstance.Text;
                string author      = MMDForm.authorInstance.Text;
                string version     = MMDForm.versionInstance.Text;
                string description = MMDForm.descriptionInstance.Text;

                // parse the ini file
                loadingBar.SetLoadingStatus("writing ini data to metadata.ini");

                INIManage.Parse(MMDForm.modPath + "\\.osml\\metadata.ini",
                                new string[4]
                {
                    "displayName",
                    "author",
                    "version",
                    "description"
                },
                                new string[4]
                {
                    displayName,
                    author,
                    version,
                    description
                }
                                );

                loadingBar.SetLoadingStatus("saving icon");

                // save the icon to the icon path
                MMDForm.icon.Image.Save(MMDForm.modPath + "\\.osml\\icon.png");

                loadingBar.SetLoadingStatus("almost done!");

                Console.Beep();
                MessageBox.Show("All done!");

                // close MMDForm and tidy up
                loadingBar.Dispose();
                MMDForm.instance.Close();
                Audio.Stop();
                Audio.PlaySound("sfx_back", false);
            }

            catch (Exception ex)
            {
                string message = "An exception was encountered:\n" + ex.Message +
                                 "\n------------------\n" + ex.ToString();
                Logger.WriteLine(message);
                MessageBox.Show(message);
            }
        }