Пример #1
0
        public static Manifest GetManifest(bool forceLoad = false)
        {
            // Check if already staticly loaded
            if (_manifest != null && !forceLoad)
            {
                return(_manifest);
            }

            // Find config dir and manifest file
            string maFile = Path.Combine(Program.SteamGuardPath, "manifest.json");

            // If there's no config dir, create it
            if (!Directory.Exists(Program.SteamGuardPath))
            {
                _manifest = _generateNewManifest();
                return(_manifest);
            }

            // If there's no manifest, create it
            if (!File.Exists(maFile))
            {
                if (Program.Verbose)
                {
                    Console.WriteLine("warn: No manifest file found at {0}", maFile);
                }
                bool?createNewManifest = Program.SteamGuardPath ==
                                         Program.defaultSteamGuardPath.Replace("~", Environment.GetEnvironmentVariable("HOME")) ? true : (bool?)null;
                while (createNewManifest == null)
                {
                    Console.Write($"Generate new manifest.json in {Program.SteamGuardPath}? [Y/n]");
                    var answer = Console.ReadLine();
                    if (answer != null)
                    {
                        createNewManifest = !answer.StartsWith("n") && !answer.StartsWith("N");
                    }
                }
                if ((bool)createNewManifest)
                {
                    _manifest = _generateNewManifest(true);
                    return(_manifest);
                }
                return(null);
            }

            try
            {
                string manifestContents = File.ReadAllText(maFile);
                _manifest = JsonConvert.DeserializeObject <Manifest>(manifestContents);

                if (_manifest.Encrypted && _manifest.Entries.Count == 0)
                {
                    _manifest.Encrypted = false;
                    _manifest.Save();
                }

                _manifest.RecomputeExistingEntries();

                return(_manifest);
            }
            catch (Exception ex)
            {
                Console.WriteLine("error: Could not open manifest file: {0}", ex.ToString());
                return(null);
            }
        }
Пример #2
0
        private static Manifest _generateNewManifest(bool scanDir = false)
        {
            if (Program.Verbose)
            {
                Console.WriteLine("Generating new manifest...");
            }

            // No directory means no manifest file anyways.
            Manifest newManifest = new Manifest();

            newManifest.Encrypted = false;
            newManifest.PeriodicCheckingInterval      = 5;
            newManifest.PeriodicChecking              = false;
            newManifest.AutoConfirmMarketTransactions = false;
            newManifest.AutoConfirmTrades             = false;
            newManifest.Entries  = new List <ManifestEntry>();
            newManifest.FirstRun = true;

            // Take a pre-manifest version and generate a manifest for it.
            if (scanDir)
            {
                if (Directory.Exists(Program.SteamGuardPath))
                {
                    DirectoryInfo dir   = new DirectoryInfo(Program.SteamGuardPath);
                    var           files = dir.GetFiles();

                    foreach (var file in files)
                    {
                        if (file.Extension != ".maFile")
                        {
                            continue;
                        }

                        string contents = File.ReadAllText(file.FullName);
                        try
                        {
                            SteamGuardAccount account  = JsonConvert.DeserializeObject <SteamGuardAccount>(contents);
                            ManifestEntry     newEntry = new ManifestEntry()
                            {
                                Filename = file.Name,
                                SteamID  = account.Session.SteamID
                            };
                            newManifest.Entries.Add(newEntry);
                        }
                        catch (Exception ex)
                        {
                            if (Program.Verbose)
                            {
                                Console.WriteLine("warn: {0}", ex.Message);
                            }
                        }
                    }

                    if (newManifest.Entries.Count > 0)
                    {
                        newManifest.Save();
                        newManifest.PromptSetupPassKey(true);
                    }
                }
            }

            if (newManifest.Save())
            {
                return(newManifest);
            }

            return(null);
        }