/// <summary>
        /// Reads a modinfo.json file and parses the data into a new mod object.
        /// <para>After sucessfully getting the data, it will execute ValidateAndAddMod()</para>
        /// </summary>
        /// <param name="modJsonFile"></param>
        public void Json_ReadModFile(string modJsonFile, bool bypassValidation = false, bool deleteJson = true)
        {
            //create a new mod object
            Mod newMod = GetJsonData(modJsonFile);

            //if the new mod is null, do not continue!
            if (newMod == null)
            {
                return;
            }

            if (deleteJson)
            {
                //delete the modJsonFile since we don't need it anymore
                IOManagement.DeleteFile(modJsonFile);
            }

            //bypass the validation stage and just add the mod anyway
            //(for when this function is called to gather mods from the mod folder on startup)
            if (bypassValidation)
            {
                mods.Add(newMod);

                if (CheckIfModFilesExist(newMod) == false)
                {
                    ExtractModZipFileContents_ToDirectory(newMod);
                }
            }
            else
            {
                //otherwise, validate the mod. if its sucessful it will be added
                ValidateAndAddMod(newMod);
            }
        }
        /// <summary>
        /// Removes a mod from the mod manager.
        /// <para>Will prompt the user if they want to remove the file.</para>
        /// <para>If yes, it will remove the files associated with the mod on the disk, and remove it from the mod manager.</para>
        /// </summary>
        /// <param name="selectedIndex"></param>
        public void RemoveMod(int selectedIndex, bool ignorePrompt = false)
        {
            //obtain the given mod at the selected index
            Mod selectedMod = mods[selectedIndex];

            if (ignorePrompt)                                              //ignores the confirmation prompt and removes the mod object, mod contents, and json file
            {
                RemoveModFiles(selectedMod);                               //remove the files associated with the mod
                IOManagement.DeleteFile(selectedMod.ModInfoJson_FilePath); //remove the modinfo.json file
                mods.Remove(selectedMod);                                  //remove the mod from the list in memory
            }
            else
            {
                //description for the confirmation prompt
                string promptDescription = string.Format("Are you sure you want to remove '{0}'?", selectedMod.ModDisplayName);

                //prompt the user about removing the mod
                if (MessageBoxes.Info_Confirm(promptDescription, "Remove Mod"))
                {
                    RemoveModFiles(selectedMod);                               //remove the files associated with the mod
                    IOManagement.DeleteFile(selectedMod.ModInfoJson_FilePath); //remove the modinfo.json file
                    mods.Remove(selectedMod);                                  //remove the mod from the list in memory
                }
            }
        }
        /// <summary>
        /// Removes all mods from the mod manager.
        /// <para>Will prompt the user if they wish to proceed.</para>
        /// <para>If yes, it will remove all mods from the manager and the files associated with each from the disk.</para>
        /// </summary>
        public void PurgeMods()
        {
            //prompt the user upfront if they wish to remove all of the mods in the directory
            if (MessageBoxes.Warning_Confirm("Are you sure you want to purge the mod directory? This will remove all the mod files currently installed. This action can't be reverted.", "Purge Mods"))
            {
                //get the game mods location of the current game version
                string dir = appSettings.Get_Current_GameVersionSettings_ModsLocation();

                //loop through the mod list first and remove the files in relation to each mod
                foreach (Mod mod in mods)
                {
                    foreach (string modfile in mod.ModFiles)
                    {
                        string modfile_pathOnDisk = Path.Combine(appSettings.Get_Current_GameVersionSettings_ModsLocation(), modfile);
                        IOManagement.DeleteFile(modfile_pathOnDisk);
                    }
                }

                //loop through the mods directory again to get the .json files, and remove them
                foreach (string modJsonFile in IOManagement.GetFilesPathsByExtension(dir, ".json"))
                {
                    IOManagement.DeleteFile(modJsonFile);
                }

                //clear the mods list
                mods.Clear();
            }
        }
        /// <summary>
        /// Replaces an existing mod with a new mod.
        /// <para>Also replaces the files associated with the existing mod with the new one.</para>
        /// </summary>
        /// <param name="orignalMod"></param>
        /// <param name="newMod"></param>
        private void ReplaceMod(Mod orignalMod, Mod newMod)
        {
            RemoveModFiles(orignalMod);
            IOManagement.DeleteFile(orignalMod.ModInfoJson_FilePath);
            mods.Remove(orignalMod);

            ExtractModZipFileContents_ToDirectory(newMod);
            mods.Add(newMod);
        }
        /// <summary>
        /// Remove the mod files assoicated with the given mod on the disk.
        /// </summary>
        /// <param name="mod"></param>
        public void RemoveModFiles(Mod mod)
        {
            //loop through each of the mod files detailed in the mods .json file
            foreach (string modfile in mod.ModFiles)
            {
                string modfile_pathOnDisk = Path.Combine(appSettings.Get_Current_GameVersionSettings_ModsLocation(), modfile);

                if (File.Exists(modfile_pathOnDisk))
                {
                    IOManagement.DeleteFile(modfile_pathOnDisk);
                }
            }
        }
        /// <summary>
        /// Calls the main method to convert a D3DTX to DDS
        /// </summary>
        public void ConvertToDDS()
        {
            //call the main function
            converter.App_Convert_D3DTX_Mode();

            //after we finish converting, delete the original .d3dtx files
            foreach (string path in IOManagement.GetFilesPathsByExtension(workingDirectory.workingDirectoryPath, ".d3dtx"))
            {
                IOManagement.DeleteFile(path);
            }

            //refresh the directory
            Refresh_WorkingDirectory();

            //update our UI
            mainWindow.UpdateUI();
        }
        /// <summary>
        /// Extracts the mod file zip contents to the Game Mods directory.
        /// </summary>
        public void ExtractModZipFileContents_ToDirectory(Mod mod)
        {
            //extract entire zip file's contents to the mods folder
            using (ZipArchive archive = ZipFile.OpenRead(modZipFilePath))
            {
                foreach (ZipArchiveEntry entry in archive.Entries)
                {
                    //check if the given entry has an extension, i.e. check if it is a file and not a folder (we want to extract the contents, not the folder)
                    if (Path.HasExtension(entry.FullName))
                    {
                        // Gets the full path to ensure that relative segments are removed.
                        string modFile_extractedFromArchive = Path.GetFullPath(Path.Combine(appSettings.Get_Current_GameVersionSettings_ModsLocation(), entry.Name));

                        //checks the extension for a .json file, if one is found then it sets it for the mod
                        if (entry.FullName.EndsWith(".json", StringComparison.OrdinalIgnoreCase))
                        {
                            mod.ModInfoJson_FilePath = modFile_extractedFromArchive;
                        }

                        // Ordinal match is safest, case-sensitive volumes can be mounted within volumes that are case-insensitive.
                        if (modFile_extractedFromArchive.StartsWith(appSettings.Get_Current_GameVersionSettings_ModsLocation(), StringComparison.Ordinal))
                        {
                            //if there is an existing modfile that shares the same path/extension and everything, remove it
                            //NOTE: in the future, want to prompt the user about replacing mod files
                            if (File.Exists(modFile_extractedFromArchive))
                            {
                                IOManagement.DeleteFile(modFile_extractedFromArchive);
                            }

                            foreach (string gameDirFile in mod.ModFilesGameDirectory)
                            {
                                if (gameDirFile.Equals(entry.Name))
                                {
                                }
                            }

                            //extract the given entry to the game mods directory
                            entry.ExtractToFile(modFile_extractedFromArchive);
                        }
                    }
                }
            }
        }
Пример #8
0
        /// <summary>
        /// Writes existing values of the App Settings objects into the config file.
        /// </summary>
        public void WriteToFile()
        {
            if (File.Exists(configFile_file_location))
            {
                IOManagement.DeleteFile(configFile_file_location);
            }

            //open a stream writer to create the text file and write to it
            using (StreamWriter file = File.CreateText(configFile_file_location))
            {
                //get our json seralizer
                JsonSerializer serializer = new JsonSerializer();

                List <object> jsonObjects = new List <object>();
                jsonObjects.Add(appSettingsFile);
                jsonObjects.Add(GameVersionSettings);

                //seralize the data and write it to the configruation file
                serializer.Formatting = Formatting.Indented;
                serializer.Serialize(file, jsonObjects);
            }
        }
        /// <summary>
        /// Reads a mod zip file.
        /// <para>Extracts the modinfo.json file</para>
        /// </summary>
        /// <param name="newModZipFilePath"></param>
        public void ReadModZipFile(string newModZipFilePath)
        {
            modZipFilePath = newModZipFilePath;
            modZipFilePath = Path.GetFullPath(modZipFilePath);
            string modZipFile_ParentDirectory   = Path.GetDirectoryName(modZipFilePath);
            string modJson_extractedFromArchive = "";

            // Ensures that the last character on the extraction path is the directory separator char.
            if (!modZipFile_ParentDirectory.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal))
            {
                modZipFile_ParentDirectory += Path.DirectorySeparatorChar;
            }

            using (ZipArchive archive = ZipFile.OpenRead(modZipFilePath))
            {
                foreach (ZipArchiveEntry entry in archive.Entries)
                {
                    if (entry.FullName.EndsWith(".json", StringComparison.OrdinalIgnoreCase))
                    {
                        // Gets the full path to ensure that relative segments are removed.
                        modJson_extractedFromArchive = Path.GetFullPath(Path.Combine(modZipFile_ParentDirectory, entry.Name));

                        if (File.Exists(modJson_extractedFromArchive))
                        {
                            IOManagement.DeleteFile(modJson_extractedFromArchive);
                        }

                        // Ordinal match is safest, case-sensitive volumes can be mounted within volumes that are case-insensitive.
                        if (modJson_extractedFromArchive.StartsWith(modZipFile_ParentDirectory, StringComparison.Ordinal))
                        {
                            entry.ExtractToFile(modJson_extractedFromArchive);
                        }
                    }
                }
            }

            //after extraction, read the json file
            Json_ReadModFile(modJson_extractedFromArchive);
        }
Пример #10
0
 /// <summary>
 /// Updates the changes to the app config file by replacing it and writing a new one. (there is a better way of doing it, but this works fine)
 /// </summary>
 public void UpdateChangesToFile()
 {
     IOManagement.DeleteFile(configFile_file_location);
     WriteToFile();
 }
        /// <summary>
        /// Checks the given mod's contents with all the other mod's contents found in the main mods list.
        /// </summary>
        /// <param name="newMod"></param>
        public void CheckModContents_WithExistingMods(Mod newMod, bool addMod = false)
        {
            List <Mod>    conflictingMods     = new List <Mod>();    //temp list for the conflicting mods
            List <string> conflictingModNames = new List <string>(); //temp list for the conflicting mods names (for the ui prompt)
            List <string> conflictingModFiles = new List <string>(); //temp list for the conflicting mods files (for the ui prompt)

            //loop through the mod list
            foreach (Mod mod in mods)
            {
                //create a boolean that states whether or not the given mod has conflicts
                bool hasConflictingFiles = false;

                //loop through the mod files for the current mod in the loop
                foreach (string file in mod.ModFiles)
                {
                    //loop through each 'newModFile' and check each one with the given mod 'file'
                    foreach (string newModFile in newMod.ModFiles)
                    {
                        if (file.Equals(newModFile))
                        {
                            hasConflictingFiles = true;
                            conflictingModFiles.Add(file);
                        }
                    }
                }

                //if there are conflicting files, add the current mod and its name to the list
                if (hasConflictingFiles)
                {
                    conflictingMods.Add(mod);
                    conflictingModNames.Add(mod.ModDisplayName);
                }
            }

            //if there are conflicting mods
            if (conflictingMods.Count != 0)
            {
                //for prompt ui
                string conflictingModsMessage     = string.Join(", ", conflictingModNames);
                string conflictingModFilesMessage = string.Join(", ", conflictingModFiles);
                string finalMessage = string.Format("{0} has conflicts with the following mods! {1}. They share the following files! {2}. Do you want to remove the conflicting mods?", newMod.ModDisplayName, conflictingModsMessage, conflictingModFilesMessage);

                //notify the user about the conflicts, if they take action (press yes) it will remove the conflicting mods from the list, and removes the respective files and .json files
                if (MessageBoxes.Error_Confirm(finalMessage, "Mod Conflicts!"))
                {
                    foreach (Mod mod in conflictingMods)
                    {
                        RemoveModFiles(mod);
                        IOManagement.DeleteFile(mod.ModInfoJson_FilePath);
                        mods.Remove(mod);
                    }
                }

                return;
            }

            //if everything passes, add the mod (if the boolean on the function call has been set)
            if (addMod)
            {
                ExtractModZipFileContents_ToDirectory(newMod);
                mods.Add(newMod);
            }
        }
Пример #12
0
        /// <summary>
        /// Gets the file icon of an .exe
        /// </summary>
        /// <param name="fileLocation"></param>
        /// <returns></returns>
        private ImageSource GetFileIcon(string fileLocation)
        {
            //extract icon
            IconExtractor iconExtractor = new IconExtractor(fileLocation);

            //get main icon
            Icon icon = iconExtractor.GetIcon(0);

            //split the icon (as there are multiple sizes embeded)
            Icon[] splitIcons = IconUtil.Split(icon);

            //dispose of the original icon object since we no longer need it
            icon.Dispose();

            //the highest quality icon, will be assigned later
            Icon iconHQ;

            //pixel width, will be changed through iterations and compared
            int width = 0;

            //the index of the highest quality one we find in the list
            int hqIndex = 0;

            //run a loop through the icon list to get highest quality icon
            for (int i = 0; i < splitIcons.Length; i++)
            {
                //if the pixel width is bigger than our width variable then assign it
                if (splitIcons[i].Width > width)
                {
                    //assign the pixel width (used for comparison later)
                    width = splitIcons[i].Width;

                    //get the index of the element
                    hqIndex = i;
                }
            }

            //if the loop finds the one with the highest quality, then use it using the hq index
            iconHQ = splitIcons[hqIndex];

            //convert the icon to a bitmap
            Bitmap bitmap = IconUtil.ToBitmap(iconHQ);

            //create a temporary path for it
            string tempPath = appSettings.Get_App_ConfigDirectory() + "tempIconPreview.bmp";

            //if there is already a file of the same name, get rid of it
            if (System.IO.File.Exists(tempPath))
            {
                IOManagement.DeleteFile(tempPath);
            }

            //save the bitmap to the temp path we defined
            bitmap.Save(tempPath);

            //clear the original object if it isn't already
            if (bitmapimage != null)
            {
                bitmapimage = null;
            }

            //initallize our bitmap image object with a new one (not the same as the bitmap we defined prior)
            bitmapimage = new BitmapImage();
            bitmapimage.BeginInit();                                       //initalize the image
            bitmapimage.UriSource   = new Uri(tempPath, UriKind.Absolute); //set the path
            bitmapimage.CacheOption = BitmapCacheOption.OnLoad;            //cache the image since we only need it once
            bitmapimage.EndInit();                                         //end the initalization

            //return the final image
            return(bitmapimage);
        }