private void CreateAddonList()
 {
     addonList         = AcfFile.CreateNew();
     addonListBaseNode = new AcfFile.CompoundNode(CommonConsts.AddonListAcfRootKey, addonList.Root);
     addonList.Root.Add(addonListBaseNode);
     IsAddonListCreated = true;
 }
 public AddonsListTxt(string gameDir)
 {
     IsAddonListCreated = false;
     filePath           = Path.Combine(gameDir, CommonConsts.L4d2MainSubdirName, CommonConsts.AddonListTxtFileName);
     try {
         using (var reader = new StreamReader(filePath, Encoding.Default)) {
             addonList         = AcfFile.ParseString(reader.ReadToEnd(), false);
             addonListBaseNode = addonList.Root.GetChild(CommonConsts.AddonListAcfRootKey) as AcfFile.CompoundNode;
             if (addonListBaseNode == null)
             {
                 Debug.WriteLine("Warning: Syntax error within addonlist.txt.");
                 throw new LoadingException();
             }
         }
         dirty = false;
     } catch (FileNotFoundException e) {
         Debug.WriteLine("Warning: Addonlist.txt is not found and will be created");
         Debug.WriteLine(e);
         CreateAddonList();
     } catch (Exception e) {
         Debug.WriteLine("Warning: Addonlist.txt cannot be read, some features would be inaccessible.");
         Debug.WriteLine(e);
         throw new LoadingException();
     }
 }
        private static DirectoryInfo?GetGameFolder(string gameName, IReadOnlyCollection <DirectoryInfo> appFolders)
        {
            foreach (var(appFolder, acfFile) in appFolders
                     .SelectMany(appFolder =>
                                 appFolder
                                 .GetFiles(searchPattern: "*.acf", SearchOption.TopDirectoryOnly)
                                 .Select(acfFile => (appFolder, acfFile))))
            {
                var fileContent = File.ReadAllText(acfFile.FullName);

                var acfEntry = AcfFile.Parse(fileContent);

                if (acfEntry.TryGetValue("name", out var name) && name.Value == gameName)
                {
                    if (acfEntry.TryGetValue("installdir", out var installFolder))
                    {
                        var fullPath   = Path.Combine(appFolder.FullName, "common", installFolder.Value);
                        var gameFolder = new DirectoryInfo(fullPath);

                        if (gameFolder.Exists)
                        {
                            return(gameFolder);
                        }
                        break;
                    }

                    break;
                }
            }

            return(null);
        }
        public static bool RunTestPair(string input, string expected)
        {
            var  got = AcfFile.TestLexer(input);
            bool ret = String.Equals(expected, got);

            Console.WriteLine(ret ? "Test passed." : "Test failed.");
            Console.WriteLine(input);
            Console.WriteLine("======");
            Console.WriteLine(got);
            Console.WriteLine("======");
            return(ret);
        }
        private static IReadOnlyCollection <DirectoryInfo> GetSteamAppFolders(DirectoryInfo steamDirectory)
        {
            const string steamApps = "steamapps";

            // Only 1 Steam directory per drive
            var defaultAppsFolder = new DirectoryInfo(Path.Combine(steamDirectory.FullName, steamApps));

            if (!defaultAppsFolder.Exists)
            {
                throw new DirectoryNotFoundException("The default steam library folder could not be found");
            }

            var libraryFolderMeta = defaultAppsFolder.GetFiles(
                searchPattern: "libraryfolders.vdf", searchOption: SearchOption.TopDirectoryOnly)
                                    .FirstOrDefault();

            if (libraryFolderMeta == null)
            {
                return new List <DirectoryInfo> {
                           defaultAppsFolder
                }
            }
            ;

            var metaContent    = File.ReadAllText(libraryFolderMeta.FullName);
            var libraryFolders = AcfFile.Parse(metaContent);

            return(libraryFolders.Keys
                   .Where(k => int.TryParse(k, out _)) // The additional library folders is identified by a number as a string e.g "1"
                   .Select(k => libraryFolders[k])
                   .Aggregate(new List <DirectoryInfo>(), (folders, acfEntry) =>
            {
                // Check if the defined folder is exist
                var path = Path.Combine(acfEntry.Value, steamApps);
                if (Directory.Exists(path))
                {
                    folders.Add(new DirectoryInfo(path));
                }

                return folders;
            })
                   .Append(defaultAppsFolder)
                   .ToList());
        }
Beispiel #6
0
        private static bool RunTestPair(string input, string expected)
        {
            var file = AcfFile.ParseString(input, false);
            // Use LF.
            // https://stackoverflow.com/questions/4855576/streamwriter-end-line-with-lf-rather-than-crlf
            var writer = new StringWriter {
                NewLine = "\n"
            };

            foreach (var node in file.Root.Value)
            {
                PrintNodeRecursive(node, writer);
            }
            var got = writer.ToString();

            Console.WriteLine("==========");
            Console.WriteLine(input);
            Console.WriteLine("----------");
            Console.WriteLine(got);
            Console.WriteLine();
            return(String.Equals(expected, got));
        }
Beispiel #7
0
        public void DeleteGameData()
        {
            File.Delete(AcfFile);
            TransferManager.Instance.AcfFileWatchList.Add(AcfFile.ToLower());

            try
            {
                DeleteDirectoryTree(GameDir, true);
            }
            catch (Exception ex)
            {
                Utils.Logging.Logger.Error(string.Format("Error Deleting tree: {0}", GameDir), ex);
                Task.Run(() =>
                {
                    System.Windows.MessageBox.Show("Cleanup failed. You need to manually delete the directory.\n\nPress Ok to open this directory in explorer.", "Cleanup failed", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Exclamation, System.Windows.MessageBoxResult.OK);
                    try
                    {
                        System.Diagnostics.Process.Start(GameDir);
                    }
                    catch (Exception) { }
                });
            }
        }
        public static string FindGameInLibraries(string baseDir)
        {
            // Look into steam apps directory.
            // Ahh combine.
            // https://stackoverflow.com/questions/961704/how-do-i-join-two-paths-in-c
            string steamAppsPath = Path.Combine(baseDir, CommonConsts.SteamAppsDirectoryName);

            // Check the default library.
            string gamePath = FindGameInLibrary(steamAppsPath);

            if (gamePath == null)
            {
                string confPath = Path.Combine(steamAppsPath, CommonConsts.SteamLibraryConfigVdfFileName);
                string confTxt  = File.ReadAllText(confPath);
                var    conf     = AcfFile.ParseString(confTxt, true);
                var    infoNode = conf.GetNodeByPath(CommonConsts.SteamLibraryConfigVdfFileRootNode);
                foreach (var node in (infoNode as AcfFile.CompoundNode).Value)
                {
                    if (!(node is AcfFile.LeafNode))
                    {
                        continue;
                    }
                    try {
                        int.Parse(node.Key);
                        gamePath = FindGameInLibrary(
                            Path.Combine((node as AcfFile.LeafNode).Value, CommonConsts.SteamAppsDirectoryName)
                            );
                        if (gamePath != null)
                        {
                            break;
                        }
                    } catch (Exception) { }
                }
            }

            return(gamePath);
        }
Beispiel #9
0
 public void TestMethod7()
 {
     Console.WriteLine(
         AcfFile.ParseString(File.ReadAllText(@"E:\Program Files (x86)\Steam\steamapps\appmanifest_243730.acf"), false).ToString()
         );
 }