示例#1
0
文件: AutoSave.cs 项目: SynPDX/Prod
        private static bool Backup()
        {
            if (m_Backups.Length == 0)
            {
                return(false);
            }

            string root = Path.Combine(Core.BaseDirectory, "Backups/Automatic");

            if (!Directory.Exists(root))
            {
                Directory.CreateDirectory(root);
            }

            string tempRoot = Path.Combine(Core.BaseDirectory, "Backups/Temp");

            if (Directory.Exists(tempRoot))
            {
                Directory.Delete(tempRoot, true);
            }

            string[] existing = Directory.GetDirectories(root);

            bool anySuccess = existing.Length == 0;

            for (int i = 0; i < m_Backups.Length; ++i)
            {
                DirectoryInfo dir = Match(existing, m_Backups[i]);

                if (dir == null)
                {
                    continue;
                }

                if (i > 0)
                {
                    try
                    {
                        dir.MoveTo(Path.Combine(root, m_Backups[i - 1]));

                        anySuccess = true;
                    }
                    catch { }
                }
                else
                {
                    bool delete = true;

                    try
                    {
                        dir.MoveTo(tempRoot);

                        delete = !ArchivedSaves.Process(tempRoot);
                    }
                    catch { }

                    if (delete)
                    {
                        try { dir.Delete(true); }
                        catch { }
                    }
                }
            }

            string saves = Path.Combine(Core.BaseDirectory, "Saves");

            if (Directory.Exists(saves))
            {
                Directory.Move(saves, Path.Combine(root, m_Backups[m_Backups.Length - 1]));
            }

            return(anySuccess);
        }
示例#2
0
        private static void Backup()
        {
            if (m_Backups.Length == 0)
            {
                return;
            }

            string root = Path.Combine(Core.BaseDirectory, "Backups/Automatic");

            if (!Directory.Exists(root))
            {
                Directory.CreateDirectory(root);
            }

            string[] existing = Directory.GetDirectories(root);

            for (int i = 0; i < m_Backups.Length; ++i)
            {
                DirectoryInfo dir = Match(existing, m_Backups[i]);

                if (dir == null)
                {
                    continue;
                }

                if (i > 0)
                {
                    string timeStamp = FindTimeStamp(dir.Name);

                    if (timeStamp != null)
                    {
                        try
                        {
                            dir.MoveTo(FormatDirectory(root, m_Backups[i - 1], timeStamp));
                        }
                        catch
                        {
                        }
                    }
                }
                else
                {
                    try
                    {
                        dir.Delete(true);
                    }
                    catch
                    {
                    }
                }
            }

            string saves = Path.Combine(Core.BaseDirectory, "Saves");

            if (Directory.Exists(saves))
            {
                var saveDir = FormatDirectory(root, m_Backups[m_Backups.Length - 1], GetTimeStamp());

                Directory.Move(saves, saveDir);

                if (ArchivedSaves.Enabled)
                {
                    ArchivedSaves.RunArchive(saveDir);
                }
            }
        }