コード例 #1
0
ファイル: PathLogic.cs プロジェクト: rithien/plugin-sdk-tools
        static public void ForAllFolders(string dirLoc, bool recursive, FolderCallback cb)
        {
            try
            {
                var directoryNames = Directory.GetDirectories(dirLoc);
                foreach (string dirName in directoryNames)
                {
                    // Notify.
                    cb(dirName);

                    if (recursive)
                    {
                        // Go into that directory.
                        DirectoryInfo dir = new DirectoryInfo(dirName);
                        if ((dir.Attributes & FileAttributes.Hidden) == 0)
                        {
                            ForAllFolders(dirName, recursive, cb);
                        }
                    }
                }
            }
            catch (Exception)
            {
                return;
            }
        }
コード例 #2
0
ファイル: PathLogic.cs プロジェクト: rithien/plugin-sdk-tools
        static public string ScanForGTAGameFolder(IsGameFolderCallback cb)
        {
            string theFolder = null;

            FolderCallback findIterCB = (findLoc) =>
            {
                if (cb(findLoc))
                {
                    theFolder = findLoc;
                    throw new FoundFolderException(findLoc);
                }
            };

#if NETFW_4
            string programFilesFolder = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
#else
            string programFilesFolder = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
#endif
            ForAllFolders(programFilesFolder, false, findIterCB);

            if (theFolder == null)
            {
                // Check the Rockstar Games folder.
                string rockstarGamesFolder = programFilesFolder + "\\Rockstar Games";

                ForAllFolders(rockstarGamesFolder, false, findIterCB);
            }

            if (theFolder == null)
            {
                // At last, try the default steam games directory.
                string steamGamesFolder = programFilesFolder + "\\Steam\\steamapps\\common";

                ForAllFolders(steamGamesFolder, false, findIterCB);
            }

            if (theFolder == null)
            {
                // Should also scan inside the D: drive.
                ForAllFolders("D:\\", true, findIterCB);
            }

            // Return anything we found.
            return(theFolder);
        }