/// <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>
        /// 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>
        /// Begins the conversion process. Gathers the files found in the texture folder path, filters them, and converts each one.
        /// </summary>
        /// <param name="texPath"></param>
        /// <param name="resultPath"></param>
        public static void Convert_D3DTX_Bulk(string texPath, string resultPath)
        {
            ConsoleFunctions.SetConsoleColor(ConsoleColor.Black, ConsoleColor.Yellow);
            Console.WriteLine("Collecting Files..."); //notify the user we are collecting files

            //gather the files from the texture folder path into an array
            List <string> textures = new List <string>(Directory.GetFiles(texPath));

            ConsoleFunctions.SetConsoleColor(ConsoleColor.Black, ConsoleColor.Yellow);
            Console.WriteLine("Filtering Textures..."); //notify the user we are filtering the array

            //filter the array so we only get .d3dtx files
            textures = IOManagement.FilterFiles(textures, D3DTX_Master.d3dtxExtension);

            //if no d3dtx files were found, abort the program from going on any further (we don't have any files to convert!)
            if (textures.Count < 1)
            {
                ConsoleFunctions.SetConsoleColor(ConsoleColor.Black, ConsoleColor.Red);
                Console.WriteLine("No .d3dtx files were found, aborting."); //notify the user we found x amount of d3dtx files in the array
                Console.ResetColor();
                return;
            }

            ConsoleFunctions.SetConsoleColor(ConsoleColor.Black, ConsoleColor.Green);
            Console.WriteLine("Found {0} Textures.", textures.Count.ToString()); //notify the user we found x amount of d3dtx files in the array
            Console.WriteLine("Starting...");                                    //notify the user we are starting

            Thread[] threads = new Thread[textures.Count];

            int index = 0;

            //run a loop through each of the found textures and convert each one
            foreach (string texturePath in textures)
            {
                //build the path for the resulting file
                string textureFileName     = Path.GetFileName(texturePath);                                    //get the file name of the file + extension
                string textureFileNameOnly = Path.GetFileNameWithoutExtension(texturePath);
                string textureResultPath   = resultPath + "/" + textureFileNameOnly + DDS_Master.ddsExtension; //add the file name to the resulting folder path, this is where our converted file will be placed

                ConsoleFunctions.SetConsoleColor(ConsoleColor.Black, ConsoleColor.White);
                Console.WriteLine("||||||||||||||||||||||||||||||||");
                ConsoleFunctions.SetConsoleColor(ConsoleColor.Black, ConsoleColor.Blue);
                Console.WriteLine("Converting '{0}'...", textureFileName); //notify the user are converting 'x' file.
                Console.ResetColor();

                //var thre = new Thread(() => ConvertTexture_FromD3DTX_ToDDS(textureFileName, texture, textureResultPath));
                //thre.IsBackground = true;
                //thre.
                //thre.Start();

                //runs the main method for converting the texture
                ConvertTexture_FromD3DTX_ToDDS(texturePath, textureResultPath);

                ConsoleFunctions.SetConsoleColor(ConsoleColor.Black, ConsoleColor.Green);
                Console.WriteLine("Finished converting '{0}'...", textureFileName); //notify the user we finished converting 'x' file.
                ConsoleFunctions.SetConsoleColor(ConsoleColor.Black, ConsoleColor.White);
                index++;
            }
        }
        /// <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);
        }
Exemplo n.º 6
0
        public void Set_Current_GameVersionSettings_GameExeLocation()
        {
            string newFilePath = "";

            IOManagement.GetFilePath(ref newFilePath, "Exe Files (.exe)|*.exe", "Select the Game Executable File");

            if (File.Exists(newFilePath))
            {
                current_GameVersionSettings.Game_Location    = Path.GetDirectoryName(newFilePath);
                current_GameVersionSettings.Game_LocationExe = newFilePath;
            }
        }
        /// <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);
                }
            }
        }
        //------------------------- MAIN ACTIONS -------------------------
        //------------------------- MAIN ACTIONS -------------------------
        //------------------------- MAIN ACTIONS -------------------------

        /// <summary>
        /// Adds a mod to the mod manager.
        /// <para>Will prompt the user with a file browser to select a mod file (.zip)</para>
        /// </summary>
        public void AddMod()
        {
            //create a temporary string to contain the path
            string filePath = "";

            //prompt the user with a file browser dialog
            IOManagement.GetFilePath(ref filePath, "ZIP files|*.zip", "Select a Mod File");

            //if the string is not empty (meaning the user has chosen their path) read the zip file for a modinfo.json
            if (String.IsNullOrEmpty(filePath) == false)
            {
                ReadModZipFile(filePath);
            }
        }
        public void Set_WorkingDirectory_Path()
        {
            string path = "";

            IOManagement.GetFolderPath(ref path, "Locate your folder containg your extracted .d3dtx textures.");

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            workingDirectory.GetFiles(path);

            mainWindow.UpdateUI();
        }
        /// <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>
        /// Reads the Game Mod Folder for any existing mods by looking for a modinfo.json file.
        /// <para>Will fill the mods list on the mod manager if there are any found.</para>
        /// </summary>
        public void GetModsFromFolder()
        {
            //if the game mods directory exists
            if (Directory.Exists(appSettings.Get_Current_GameVersionSettings_ModsLocation()))
            {
                //clear the list
                mods.Clear();

                //get all of the modinfo.json files found in the folder
                List <string> modJsonFilesPath = IOManagement.GetFilesPathsByExtension(appSettings.Get_Current_GameVersionSettings_ModsLocation(), ".json");

                //go through the json files list and read each one to get the data
                foreach (string jsonFilePath in modJsonFilesPath)
                {
                    Json_ReadModFile_New(jsonFilePath, true, false);
                }

                //temp list for any bad mods found
                List <Mod> badMods = new List <Mod>();

                //loop through the existing mod list and check if each mod has its assoicated files
                foreach (Mod mod in mods)
                {
                    //if the given mod does not pass the check, then its missing files! so add it to the list
                    if (CheckIfModFilesExist(mod) == false)
                    {
                        badMods.Add(mod);
                    }
                }

                //loop through the list of the bad mods that have been found and remove each one.
                //NOTE: FUTURE REFERENCE, Give the user a prompt that notifies them. For now we will handle removing the bad mod automatically.
                foreach (Mod badMod in badMods)
                {
                    RemoveMod(mods.IndexOf(badMod), true);
                }
            }

            System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                //update the UI on the main window
                mainWindow.UpdateUI();
            }));
        }
Exemplo n.º 12
0
        /// <summary>
        /// Application Settings Class, creates an AppSettings object. This is called on application startup.
        /// <para>If there is an existing config file, it will parse the data from it.</para>
        /// <para>If there is not an existing config file, or a TelltaleModLauncher directory, create a new one.</para>
        /// </summary>
        public AppSettings()
        {
            if (File.Exists(configFile_file_location))
            {
                ReadConfigFile();
            }
            else
            {
                appSettingsFile = new AppSettingsFile();
                New_GameVersionSettingsList();

                if (!Directory.Exists(configFile_directory_location))
                {
                    IOManagement.CreateDirectory(configFile_directory_location);
                }

                WriteToFile();
            }
        }
        /// <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);
                        }
                    }
                }
            }
        }
Exemplo n.º 14
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);
        }
        /// <summary>
        /// Begins the conversion process. Gathers the files found in the texture folder path, filters them, and converts each one.
        /// </summary>
        /// <param name="texPath"></param>
        /// <param name="resultPath"></param>
        public static void Convert_DDS_Bulk(string texPath, string resultPath)
        {
            ConsoleFunctions.SetConsoleColor(ConsoleColor.Black, ConsoleColor.Yellow);
            Console.WriteLine("Collecting Files..."); //notify the user we are collecting files

            //gather the files from the texture folder path into an array
            List <string> files = new List <string>(Directory.GetFiles(texPath));

            //where our dds file paths will be stored
            List <string> ddsFiles;

            ConsoleFunctions.SetConsoleColor(ConsoleColor.Black, ConsoleColor.Yellow);
            Console.WriteLine("Filtering Files..."); //notify the user we are filtering the array

            //filter the array so we only get .dds files
            ddsFiles = IOManagement.FilterFiles(files, DDS_Master.ddsExtension);

            //if none of the arrays have any files that were found, abort the program from going on any further (we don't have any files to convert!)
            if (ddsFiles.Count < 1)
            {
                ConsoleFunctions.SetConsoleColor(ConsoleColor.Black, ConsoleColor.Red);
                Console.WriteLine("No .dds files were found, aborting.");
                Console.ResetColor();
                return;
            }

            ConsoleFunctions.SetConsoleColor(ConsoleColor.Black, ConsoleColor.Green);
            Console.WriteLine("Found {0} Textures.", ddsFiles.Count.ToString()); //notify the user we found x amount of dds files in the array
            Console.WriteLine("Starting...");                                    //notify the user we are starting

            //run a loop through each of the found textures and convert each one
            foreach (string ddsFile in ddsFiles)
            {
                ConvertTexture_FromDDS_ToD3DTX(ddsFile, resultPath);
            }
        }
Exemplo n.º 17
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);
        }
 public bool CanConvertTo_D3DTX() => IOManagement.GetFilesPathsByExtension(workingDirectory.workingDirectoryPath, ".dds").Count > 0 && IOManagement.GetFilesPathsByExtension(workingDirectory.workingDirectoryPath, ".header").Count > 0;
 public bool CanConvertTo_DDS() => IOManagement.GetFilesPathsByExtension(workingDirectory.workingDirectoryPath, ".d3dtx").Count > 0;
Exemplo n.º 20
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);
            }
        }