StonehearthEditor.MainForm.checkModsFolder C# (CSharp) Method

checkModsFolder() private method

Checks if a folder is likely to be a valid mod folder.
private checkModsFolder ( string &modsFolder ) : bool
modsFolder string Full path to the folder that is to be checked.
return bool
        private bool checkModsFolder(ref string modsFolder)
        {
            if (!Directory.Exists(modsFolder))
                return false;

            // If there is at least one directory that contains a manifest.json, it's probably a valid directory
            if (Directory.EnumerateDirectories(modsFolder).Any(subDir => File.Exists(Path.Combine(subDir, "manifest.json"))))
                return true;

            // Maybe they've selected the SH root folder..?
            var subDirectory = Path.Combine(modsFolder, "mods");
            if (Directory.Exists(subDirectory) && this.checkModsFolder(ref subDirectory))
            {
                modsFolder = subDirectory;
                return true;
            }

            return false;
        }

Usage Example

Exemplo n.º 1
0
            public bool OnAccept(string newBaseModsPath, string newSteamUploadsPath)
            {
                bool modsPathAccepted = false;
                // First check that the mods directory is valid (we require it)
                var check = form.checkModsFolder(ref newBaseModsPath);

                if (check == ModFolderCheckResult.ZIPPED)
                {
                    if (UnzipMods(newBaseModsPath))
                    {
                        check = ModFolderCheckResult.VALID;
                    }
                }

                if (check == ModFolderCheckResult.VALID)
                {
                    kModsDirectoryPath = JsonHelper.NormalizeSystemPath(newBaseModsPath);
                    Properties.Settings.Default["ModsDirectory"] = kModsDirectoryPath;
                    Properties.Settings.Default.Save();
                    modsPathAccepted = true;
                }
                else if (Directory.Exists(newBaseModsPath))
                {
                    // If the directory does exist, but doesn't seem to be valid, make it a user choice
                    if (MessageBox.Show("The chosen directory does not appear to be a valid mods directory. It should contain the uncompressed stonehearth mod. Choose it anyway?", "Possibly invalid mods directory", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
                    {
                        kModsDirectoryPath = JsonHelper.NormalizeSystemPath(newBaseModsPath);
                        Properties.Settings.Default["ModsDirectory"] = kModsDirectoryPath;
                        modsPathAccepted = true;
                    }
                }
                else
                {
                    if (MessageBox.Show("Invalid mods directory chosen. Try again?", "Invalid directory", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.No)
                    {
                        modsPathAccepted = false;
                    }
                }

                // Check the steam_uploads directory (can be empty if the user is developing in the mods folder)
                var check2 = form.checkModsFolder(ref newSteamUploadsPath);

                if (check2 == ModFolderCheckResult.ZIPPED)
                {
                    if (UnzipMods(newSteamUploadsPath))
                    {
                        check2 = ModFolderCheckResult.VALID;
                    }
                }

                if (check2 == ModFolderCheckResult.VALID)
                {
                    kSteamUploadsDirectoryPath = JsonHelper.NormalizeSystemPath(newSteamUploadsPath);
                    Properties.Settings.Default["SteamUploadsDirectory"] = kSteamUploadsDirectoryPath;
                    Properties.Settings.Default.Save();
                }
                else if (Directory.Exists(newSteamUploadsPath))
                {
                    // If the directory does exist, but doesn't seem to be valid, make it a user choice
                    if (MessageBox.Show("The chosen directory does not appear to be a valid mods directory. Choose it anyway?", "Possibly invalid additional mods directory", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
                    {
                        kSteamUploadsDirectoryPath = JsonHelper.NormalizeSystemPath(newSteamUploadsPath);
                        Properties.Settings.Default["SteamUploadsDirectory"] = kSteamUploadsDirectoryPath;
                    }
                }
                else if (newSteamUploadsPath == string.Empty)
                {
                    // Accept cleaning the additional path to not show the mods in there
                    kSteamUploadsDirectoryPath = JsonHelper.NormalizeSystemPath(newSteamUploadsPath);
                    Properties.Settings.Default["SteamUploadsDirectory"] = kSteamUploadsDirectoryPath;
                }
                return(modsPathAccepted);
            }