public void LoadSteamLibraries()
        {
            String steamPath = Launcher.GetInstallPath();

            steamLibs = new List <string>();
            if (Directory.Exists(steamPath))
            {
                steamLibs.Add(steamPath);

                if (File.Exists(steamPath + "\\steamapps\\libraryfolders.vdf"))
                {
                    SourceSDK.KeyValue root = SourceSDK.KeyValue
                                              .readChunkfile(steamPath + "\\steamapps\\libraryfolders.vdf");

                    foreach (SourceSDK.KeyValue child in root.getChildren())
                    {
                        string dir = child.getValue().Replace("\\\\", "\\");
                        if (Directory.Exists(dir))
                        {
                            steamLibs.Add(dir);
                        }
                    }
                }
                else
                {
                    XtraMessageBox.Show("Could not find file \"" + steamPath + "\\steamapps\\libraryfolders.vdf\".");
                }
            }
            else
            {
                //XtraMessageBox.Show("Could not find Steam install directory.");
            }
        }
Пример #2
0
        private void readGameMenu()
        {
            string path = modPath + "\\resource\\gamemenu.res";

            Directory.CreateDirectory(Path.GetDirectoryName(path));

            if (!File.Exists(path))
            {
                MessageBox.Show("File does not exist. Creating new one");
                createGameMenu();
            }

            SourceSDK.KeyValue gameMenu = SourceSDK.KeyValue.readChunkfile(path);
            actions.Clear();
            foreach (SourceSDK.KeyValue actionKv in gameMenu.getChildren())
            {
                string label      = actionKv.getValue("label");
                string command    = actionKv.getValue("command");
                bool   inGame     = (actionKv.getValue("onlyingame") == "1");
                bool   onlySingle = (actionKv.getValue("nomulti") == "1");
                bool   onlyMulti  = (actionKv.getValue("nosingle") == "1");

                MenuAction action = new MenuAction(label, command)
                {
                    inGame = inGame, onlySingle = onlySingle, onlyMulti = onlyMulti
                };
                actions.Add(action);
            }
        }
Пример #3
0
        private static List <string> writeChunkFileTraverse(KeyValue root, int level, bool quotes)
        {
            List <string> lines = new List <string>();

            foreach (KeyValue node in root.getChildren())
            {
                lines.Add(
                    (quotes ? "\"" : string.Empty) +
                    node.getKey() +
                    (quotes ? "\"" : string.Empty) +
                    "\t\"" +
                    node.getValue() +
                    "\"");
            }

            return(lines);
        }
        public void LoadUserLibraries()
        {
            userLibs = new List <string>();
            string userPath = AppDomain.CurrentDomain.BaseDirectory + "/libraryfolders.vdf";

            if (File.Exists(userPath))
            {
                SourceSDK.KeyValue root = SourceSDK.KeyValue.readChunkfile(userPath);

                foreach (SourceSDK.KeyValue child in root.getChildren())
                {
                    string dir = child.getValue().Replace("\\\\", "\\");
                    if (Directory.Exists(dir))
                    {
                        userLibs.Add(dir);
                    }
                }
            }
        }
Пример #5
0
        private static List <string> writeChunkFileTraverse(KeyValue node, int level, bool quotes)
        {
            List <string> lines = new List <string>();

            string tabs = string.Empty;

            for (int i = 0; i < level; i++)
            {
                tabs = tabs + "\t";
            }

            if (node.isParentKey()) // It's a parent key
            {
                if (node.key != string.Empty)
                {
                    lines.Add(tabs + (quotes ? "\"" : string.Empty) + node.key + (quotes ? "\"" : string.Empty));
                    lines.Add(tabs + "{");
                }

                foreach (KeyValue entry in node.getChildren())
                {
                    lines.AddRange(writeChunkFileTraverse(entry, level + 1, quotes));
                }

                if (node.key != string.Empty)
                {
                    lines.Add(tabs + "}");
                }
            }
            else if (node.getKey() != string.Empty && node.getValue() != null)   // It's a value key
            {
                string line = tabs;
                if (node.key != string.Empty)
                {
                    line = line +
                           (quotes ? "\"" : string.Empty) +
                           node.key +
                           (quotes ? "\"" : string.Empty) +
                           "\t\"" +
                           node.value +
                           "\"";
                }
                if (node.comment != string.Empty)
                {
                    if (node.key != string.Empty)
                    {
                        line = line + "\t";
                    }

                    line = line + "//" + node.comment;
                }

                lines.Add(line);
            }
            else if (node.comment != string.Empty)   // Comment line
            {
                string line = tabs + "//" + node.comment;
                lines.Add(line);
            }
            else if (node.key == string.Empty)      // Blank line
            {
                lines.Add("");
            }

            return(lines);
        }
Пример #6
0
        public List <string> GetMountedPaths()
        {
            List <string> result = new List <string>();

            string gamePath = game.installPath;
            string modPath  = installPath;

            SourceSDK.KeyValue gameInfo    = null;
            SourceSDK.KeyValue searchPaths = null;
            switch (game.engine)
            {
            case Engine.SOURCE:
                gameInfo    = SourceSDK.KeyValue.readChunkfile(modPath + "\\gameinfo.txt");
                searchPaths = gameInfo.findChildByKey("searchpaths");
                break;

            case Engine.SOURCE2:
                gameInfo    = SourceSDK.KeyValue.readChunkfile(modPath + "\\gameinfo.gi");
                searchPaths = gameInfo.findChildByKey("searchpaths");
                break;

            case Engine.GOLDSRC:
                searchPaths = new SourceSDK.KeyValue("searchpaths");
                searchPaths.addChild(new SourceSDK.KeyValue("game", new DirectoryInfo(installPath).Name));
                searchPaths.addChild(new SourceSDK.KeyValue("game", "valve"));
                break;
            }

            foreach (SourceSDK.KeyValue searchPath in searchPaths.getChildren())
            {
                string[] keys = searchPath.getKey().Split('+');

                if (!keys.Contains("game"))
                {
                    continue;
                }

                string value = searchPath.getValue();

                switch (game.engine)
                {
                case Engine.SOURCE:
                    value = value.Replace("/", "\\");
                    if (value.Contains("|all_source_engine_paths|"))
                    {
                        value = value.Replace("|all_source_engine_paths|", gamePath + "\\");
                    }
                    else if (value.Contains("|gameinfo_path|"))
                    {
                        value = value.Replace("|gameinfo_path|", modPath + "\\");
                    }
                    else if (!Directory.Exists(value))
                    {
                        value = gamePath + "\\" + value;
                    }
                    value = value.Replace("\\\\", "\\");
                    if (value.EndsWith("/"))
                    {
                        value = value.Substring(0, value.Length - 1);
                    }

                    break;

                case Engine.SOURCE2:
                    value = gamePath + "\\game\\" + value;
                    // We can't mount the vpks because we have no vpk.exe

                    /*foreach(string file in Directory.GetFiles(value, "*.vpk", SearchOption.AllDirectories))
                     * {
                     *  string fileName = Path.GetFileNameWithoutExtension(file);
                     *  if (int.TryParse(fileName.Substring(fileName.Length - 3), out _))
                     *      continue;
                     *
                     *      result.Add(file.Replace("_dir.vpk", ".vpk"));
                     * }*/
                    break;

                case Engine.GOLDSRC:
                    value = gamePath + "\\" + value;
                    break;
                }

                result.Add(value);
            }



            return(result.Distinct().ToList());
        }