コード例 #1
0
        private void ButtonLoadSingleMod_MouseClick(object sender, MouseEventArgs e)
        {
            //create and setup an open file dialog
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Multiselect = false;
            DialogResult rep = ofd.ShowDialog();

            if (rep == DialogResult.OK)
            {
                string FilePath = ofd.FileName;

                try
                {
                    //load the mod object
                    oMod NewMod = new oMod(FilePath);


                    //mods load faster when the tab container does have to refresh while the process.
                    this.TabContainer.Visible = false;
                    Crafts.AddMod(NewMod);
                    this.TabContainer.Visible = true;

                    this.Editer.RefreshImage();
                }
                catch
                {
                    MessageBox.Show("An error occurred");
                }
            }
        }
コード例 #2
0
        //load, in the correct order, every mods (identified by the file extension) found inside a folder.
        private void LoadModsInFolder(string FolderPath)
        {
            //generate a list of every extensions associated to a fomod file.
            //System.IO.Path.GetExtension return the . and the text file path after that dot. for this reason, everything put into this list begins with a .
            List <string> extensions = new List <string>();

            extensions.Add(".fomod");
            for (int i = 1; i <= 9; i++)
            {
                extensions.Add(".fomod" + i.ToString());
                extensions.Add(".fomod" + i.ToString().PadLeft(2, "0".ToCharArray()[0]));
            }
            for (int i = 10; i <= 99; i++)
            {
                extensions.Add(".fomod" + i.ToString().PadLeft(2, "0".ToCharArray()[0]));
            }

            //get every file in this path
            List <string> EveryFilePath = System.IO.Directory.GetFiles(FolderPath).ToList();

            ////filter for fomod files.
            //this list contain, in the appropriate loading order, every mod file's path to load.
            List <string> EveryModPath = new List <string>();

            //because extension array is our first loop, the mod files will be added according to mod load order
            foreach (string ext in extensions)
            {
                //we search every file with this extension
                int index = EveryFilePath.Count - 1;
                while (index >= 0)
                {
                    //the actual file path
                    string FilePath = EveryFilePath[index];
                    try
                    {
                        //get this file's extension
                        string FileExt = System.IO.Path.GetExtension(FilePath);

                        //check if this file's extension is the extension we are actually looking for.
                        if (FileExt == ext)
                        {
                            //because this file's extension is the extension we are actually looking for, we add it to the EveryModPath list
                            EveryModPath.Add(FilePath);

                            //we remove this file from the list, because we know we won't have to analyse it anymore.
                            EveryFilePath.RemoveAt(index);
                        }
                    }
                    catch
                    {
                    }

                    //next iteration
                    index--;
                }

                //if there's no file left in the EveryFilePath list, we can stop because there's nothing left.
                if (EveryFilePath.Count <= 0)
                {
                    break;
                }
            }

            ////create the mod objects for every file
            List <oMod> listMods = new List <oMod>();

            //we create a mod for every file
            foreach (string ModFilePath in EveryModPath)
            {
                try
                {
                    //generate the mod for this file
                    oMod newmod = new oMod(ModFilePath);

                    //add the mod to the list of mod to load
                    listMods.Add(newmod);
                }
                catch
                {
                    MessageBox.Show("An error occurred when loading " + ModFilePath);
                }
            }

            ////load the mods

            //mods load faster when the tab container does have to refresh while the process.
            this.TabContainer.Visible = false;
            Crafts.AddMod(listMods);
            this.TabContainer.Visible = true;

            this.Editer.RefreshImage();
        }