Example #1
0
        private void FavoritesToFnisListToolStripMenuItemClick(object sender, EventArgs e)
        {
            // warn to scare curious users
            var dialogResult = MessageBox.Show(
                Resources.CommonString_ScareMessage,
                Resources.CommonString_Warning,
                MessageBoxButtons.YesNo);
            if (dialogResult == DialogResult.No)
            {
                return;
            }

            // start logging
            Program.Log.Write("\nGenerate FNIS List from Favorites: " + DateTime.Now.ToString("u"));

            // locate favorites
            var favoritesJsonFilePath = this.skyrimDirectory + Resources.PoserHotkeysDataPath + Resources.FavoritesJsonName;
            if (!File.Exists(favoritesJsonFilePath))
            {
                var errorMessage = "Unable to locate favorites at " + favoritesJsonFilePath;
                MessageBox.Show(errorMessage, Resources.CommonString_Error, MessageBoxButtons.OK);
                Program.Log.Write(errorMessage);
                return;
            }

            // deserialize favorites
            var favoritesJsonData = File.ReadAllText(favoritesJsonFilePath);
            var favorites = JsonUtilFavorites.Deserialize(favoritesJsonData);

            // setup output paths
            var fnisOutputDirectory = this.skyrimDirectory + Resources.AnimationsDataPath + "PoserHotkeys\\";
            var fnisOutputFilePath = fnisOutputDirectory + "FNIS_PoserHotkeys_List.txt";
            var jsonOutputDirectory = this.skyrimDirectory + Resources.PoserHotkeysDataPath;

            // ensure output directory exists
            if (!Directory.Exists(fnisOutputDirectory))
            {
                Program.Log.Write("Creating directory: " + fnisOutputDirectory);
                Directory.CreateDirectory(fnisOutputDirectory);
            }

            // generate data
            var fnisLines = new ConcurrentBag<string>();
            using (var pleaseWaitMessage = new FormPleaseWaitMessage())
            {
                pleaseWaitMessage.Show(this);
                pleaseWaitMessage.Update();
                try
                {
                    // read fnis animation defintions
                    var availablePosers = this.checkedListBoxPosers.Items.OfType<Poser>();
                    var posersList = availablePosers as IList<Poser> ?? availablePosers.ToList();
                    Parallel.ForEach(
                        posersList,
                        poser =>
                            {
                                poser.PopulateAnimationEventDictionary();
                            });

                    Program.Log.Write("FNIS AnimationEvent dictionaries populated.");
                    Program.Log.Write("Attempting to match " + favorites.stringList.favorites.Count + " favorites.");

                    // compile line matches
                    Parallel.ForEach(
                        favorites.stringList.favorites,
                        favorite =>
                            {
                                Parallel.ForEach(
                                    this.posers,
                                    poser =>
                                        {
                                            if (poser.FnisLines.ContainsKey(favorite))
                                            {
                                                fnisLines.Add(poser.FnisLines[favorite]);
                                            }
                                        });
                            });

                    Program.Log.Write("Successfully matched " + fnisLines.Count + " favorites.");

                    // write results to file
                    Program.Log.Write("Overwritting " + fnisOutputFilePath);
                    File.WriteAllLines(fnisOutputFilePath, fnisLines);

                    // generate json for favorites
                    var favoritesPoser = new Poser(Resources.FavoritesPoserName, fnisOutputDirectory);
                    favoritesPoser.PopulatePacks(false);
                    WriteJson(new List<Poser> { favoritesPoser }, jsonOutputDirectory);
                }
                catch (Exception exception)
                {
                    Program.Log.Write("Fatal Error: " + exception.Message);
                    throw;
                }
                pleaseWaitMessage.Close();
            }

            // show summary
            var summaryMessage =
                String.Format(
                    $"Generated {fnisLines.Count} animation events."
                    + $"\n\nWrote FNIS data to:\n{fnisOutputFilePath}"
                    + $"\n\nWrote json data to:\n{jsonOutputDirectory + Resources.FavoritesPoserName}.json"
                    + "\n\nYou may now run FNIS Generator for Modders.");
            MessageBox.Show(summaryMessage, Resources.CommonString_Summary, MessageBoxButtons.OK);
            this.buttonQuit.Select();
        }
Example #2
0
        // button events
        private void ButtonGenerateClick(object sender, EventArgs e)
        {
            // start logging
            Program.Log.Write("\nGenerate Data: " + DateTime.Now.ToString("u"));
            Program.Log.Write("Skip Missing Animations? " + this.checkBoxSkipMissingAnimations.Checked);
            Program.Log.Write("Delete Old Data? " + this.checkBoxClearOldJson.Checked);
            Program.Log.Write("Clear Favorites? " + this.checkBoxReseedFavorites.Checked);

            // initialize variables
            int validPoserCount;
            int emptyPoserCount;
            int poserPacksCount;
            var removedPoserCount = 0;
            var jsonOutputDirectory = this.skyrimDirectory + Resources.PoserHotkeysDataPath;

            // ensure output directory exists
            if (!Directory.Exists(jsonOutputDirectory))
            {
                Directory.CreateDirectory(jsonOutputDirectory);
            }

            // clear favorites...
            if (this.checkBoxReseedFavorites.Checked)
            {
                var favoritesJson = Directory.GetFiles(jsonOutputDirectory, Resources.FavoritesJsonName);
                if (favoritesJson.Length <= 0)
                {
                    Program.Log.Write(Resources.FavoritesJsonName + " not found.");
                }
                else
                {
                    removedPoserCount++;
                    Program.Log.Write("Deleting " + Resources.FavoritesJsonName);
                    File.Delete(favoritesJson.First());
                }
            }

            // clear old data...
            if (this.checkBoxClearOldJson.Checked)
            {
                foreach (var jsonFile in Directory.GetFiles(jsonOutputDirectory, "*.json")
                    .Where(jsonFile => !jsonFile.Contains(Resources.FavoritesJsonName)))
                {
                    removedPoserCount++;
                    Program.Log.Write("Deleting " + jsonFile);
                    File.Delete(jsonFile);
                }
            }

            // generate data...
            using (var pleaseWaitMessage = new FormPleaseWaitMessage())
            {
                pleaseWaitMessage.Show(this);
                pleaseWaitMessage.Update();
                try
                {
                    // get checked poser list
                    var checkedPosers = this.checkedListBoxPosers.CheckedItems.OfType<Poser>();
                    var checkedPosersList = checkedPosers as IList<Poser> ?? checkedPosers.ToList();

                    // extract all packs from all checked posers
                    var results = new ConcurrentBag<PopulatePacksResults>();
                    Parallel.ForEach(
                        checkedPosersList,
                        poser =>
                            {
                                results.Add(poser.PopulatePacks(this.checkBoxSkipMissingAnimations.Checked));
                            });

                    // log results
                    foreach (var result in results)
                    {
                        Program.Log.Write("\nPoser: " + result.PoserName);
                        Program.Log.Write("\tLoaded Packs: " + result.PacksAdded.Count);
                        Program.Log.Write("\tLoaded Pack Names: " + String.Join(", ", result.PacksAdded));
                        Program.Log.Write("\tLoaded Animations: " + result.AnimationsAdded.Count);
                        Program.Log.Write("\tMissing Animations: " + result.AnimationsMissing.Count);
                        Program.Log.Write("\tMissing Animations Names: " + String.Join(", ", result.AnimationsMissing));
                    }

                    // get summary counts
                    validPoserCount = results.Count(x => x.PacksAdded.Count > 0);
                    emptyPoserCount = results.Count(x => x.PacksAdded.Count <= 0);
                    poserPacksCount = results.Sum(x => x.PacksAdded.Count);

                    // write to disc
                    SeedFavoritesJson(jsonOutputDirectory);
                    WriteJson(checkedPosersList, jsonOutputDirectory);
                    Program.Log.Write("\nGeneration complete! " + DateTime.Now.ToString("u"));
                }
                catch (Exception exception)
                {
                    Program.Log.Write("Fatal Error: " + exception.Message);
                    throw;
                }
                pleaseWaitMessage.Close();
            }

            // show summary
            var summaryMessage =
                String.Format(
                      $"Generated {validPoserCount} data files containing {poserPacksCount} poser packs."
                    + $"\nSkipped {emptyPoserCount} posers that had 0 packs."
                    + $"\nRemoved {removedPoserCount} old data files."
                    + $"\n\nOutput written to:\n{jsonOutputDirectory}");
            MessageBox.Show(summaryMessage, Resources.CommonString_Summary, MessageBoxButtons.OK);
            Program.Log.Write(summaryMessage);
            this.buttonQuit.Select();
        }