コード例 #1
0
        private void GetBackupFiles()
        {
            if (!Directory.Exists(backupFolder))
            {
                DebugLog("Backup folder not found, check options!");
                return;
            }
            string[] backupFiles = Directory.GetFiles(backupFolder);
            backupSaveGames = new List <FarmSimSaveGame>();
            Regex r = new Regex(@"^" + farmsimVersion + "_(savegame[0-9]+)_[0-9]{8}-[0-9]{6}.zip$");
            Match m;

            foreach (string backupFile in backupFiles)
            {
                if (File.Exists(backupFile))
                {
                    string fileName = new FileInfo(backupFile).Name;
                    m = r.Match(fileName);
                    if (m.Success && m.Groups[1].Value != null)
                    {
                        DebugLog("Getting info from zip " + fileName);
                        using (ZipInputStream s = new ZipInputStream(File.OpenRead(backupFile)))
                        {
                            ZipEntry theEntry;
                            while ((theEntry = s.GetNextEntry()) != null)
                            {
                                if (theEntry.Name == "careerSavegame.xml")
                                {
                                    XmlDocument     gameXml = new XmlDocument();
                                    FarmSimSaveGame save    = new FarmSimSaveGame();
                                    gameXml.Load(s);

                                    save.directoryName = m.Groups[1].Value;
                                    save.backupName    = fileName;
                                    save.savegameName  = getNodeText(gameXml, "settings/savegameName");
                                    save.mapTitle      = getNodeText(gameXml, "settings/mapTitle");
                                    save.saveDate      = getNodeText(gameXml, "settings/saveDate");
                                    save.playerName    = getNodeText(gameXml, "settings/playerName");
                                    save.money         = Convert.ToInt32(getNodeText(gameXml, "statistics/money"));
                                    backupSaveGames.Add(save);
                                }
                            }
                            s.Close();
                        }
                    }
                }
            }
            backupSaveGames = backupSaveGames.OrderBy(sel => sel.directoryName, new OrdinalStringComparer()).ToList();
            treeViewBackups.BeginUpdate();
            treeViewBackups.Nodes.Clear();
            unselectableBackupNodes.Clear();
            for (int i = 0; i < backupSaveGames.Count; i++)
            {
                TreeNode newParentNode = treeViewBackups.Nodes.Add(backupSaveGames[i].backupName);
                TreeNode newChildNode  = newParentNode.Nodes.Add(String.Format("Player: {0}", backupSaveGames[i].playerName));
                unselectableBackupNodes.Add(newChildNode);
                newChildNode = newParentNode.Nodes.Add(String.Format("Name: {0}", backupSaveGames[i].savegameName));
                unselectableBackupNodes.Add(newChildNode);
                newChildNode = newParentNode.Nodes.Add(String.Format("Map: {0}", backupSaveGames[i].mapTitle));
                unselectableBackupNodes.Add(newChildNode);
                newChildNode = newParentNode.Nodes.Add(String.Format("Saved: {0}", backupSaveGames[i].saveDate));
                unselectableBackupNodes.Add(newChildNode);
                newChildNode = newParentNode.Nodes.Add(String.Format("Money: {0:n0}", backupSaveGames[i].money));
                unselectableBackupNodes.Add(newChildNode);
            }
            treeViewBackups.EndUpdate();
        }
コード例 #2
0
        private void GetSaveGames()
        {
            if (!Directory.Exists(saveGamePath))
            {
                DebugLog("Save game path not found, check options!");
                return;
            }
            mySaveGames = new List <FarmSimSaveGame>();
            string[] dirs = Directory.GetDirectories(saveGamePath);
            foreach (string dir in dirs)
            {
                //DebugLog("Examining: " + dir);
                if (Directory.Exists(dir))
                {
                    string dirName = new DirectoryInfo(dir).Name;
                    Regex  r       = new Regex("^savegame[0-9]+$");
                    Match  m       = r.Match(dirName);
                    if (m.Success)
                    {
                        DebugLog("Found save game directory: " + dirName);
                        string gameXmlFile = dir + Path.DirectorySeparatorChar + "careerSavegame.xml";

                        if (File.Exists(gameXmlFile))
                        {
                            DebugLog("Found XML " + gameXmlFile);
                            FarmSimSaveGame save = new FarmSimSaveGame();

                            XmlDocument gameXml = new XmlDocument();
                            gameXml.Load(gameXmlFile);
                            DirectoryInfo di = new DirectoryInfo(dir);
                            save.directoryName    = di.Name;
                            save.directoryChanged = di.LastWriteTime;
                            save.savegameName     = getNodeText(gameXml, "settings/savegameName");
                            save.mapTitle         = getNodeText(gameXml, "settings/mapTitle");
                            save.saveDate         = getNodeText(gameXml, "settings/saveDate");
                            save.playerName       = getNodeText(gameXml, "settings/playerName");
                            save.money            = Convert.ToInt32(getNodeText(gameXml, "statistics/money"));

                            DebugLog("adding " + save.directoryName);
                            mySaveGames.Add(save);
                        }
                    }
                }
            }
            mySaveGames = mySaveGames.OrderBy(sel => sel.directoryName, new OrdinalStringComparer()).ToList();
            treeViewSavegames.BeginUpdate();
            treeViewSavegames.Nodes.Clear();
            unselectableSaveNodes.Clear();
            for (int i = 0; i < mySaveGames.Count; i++)
            {
                DebugLog("looking at " + mySaveGames[i].directoryName);
                TreeNode newParentNode = treeViewSavegames.Nodes.Add(String.Format("{0}: {1} ({2})", mySaveGames[i].directoryName, mySaveGames[i].savegameName, mySaveGames[i].directoryChanged.ToString()));
                TreeNode newChildNode  = newParentNode.Nodes.Add(String.Format("Player: {0}", mySaveGames[i].playerName));
                unselectableSaveNodes.Add(newChildNode);
                newChildNode = newParentNode.Nodes.Add(String.Format("Map: {0}", mySaveGames[i].mapTitle));
                unselectableSaveNodes.Add(newChildNode);
                newChildNode = newParentNode.Nodes.Add(String.Format("Saved: {0}", mySaveGames[i].saveDate));
                unselectableSaveNodes.Add(newChildNode);
                newChildNode = newParentNode.Nodes.Add(String.Format("Money: {0:n0}", mySaveGames[i].money));
                unselectableSaveNodes.Add(newChildNode);

                DateTime latest = GetLatestZipDate(mySaveGames[i].directoryName);
                if (latest.CompareTo(mySaveGames[i].directoryChanged) >= 0)
                {
                    newParentNode.ForeColor = System.Drawing.Color.Green;
                    //newParentNode.NodeFont = new System.Drawing.Font(treeViewBackups.Font, System.Drawing.FontStyle.Bold);
                }
            }
            treeViewSavegames.EndUpdate();
        }