コード例 #1
0
ファイル: Backup.cs プロジェクト: HOWLYYY/OOP
        public bool CreateRestPoint(TypeRestPoint typeRestPoint, TypeStorage typeStorage)
        {
            var rp = new RecoveryPoint(files, string.Format("{0}\\myrp_", name), typeStorage, typeRestPoint);
            var p  = rest_points.Keys;

            if ((typeRestPoint == TypeRestPoint.Full && rp.AddFullRP()) ||
                (typeRestPoint == TypeRestPoint.Part && rp.AddPartRP(p.Count > 0 ? rest_points[p.Max()] : null)))
            {
                rest_points.Add(rp.date, rp);
                return(true);
            }
            return(false);
        }
コード例 #2
0
ファイル: RecoveryPoint.cs プロジェクト: HOWLYYY/OOP
        public bool AddPartRP(RecoveryPoint recoveryPoint)
        {
            if (recoveryPoint == null)
            {
                return(AddFullRP());
            }
            ZipArchive zipArchive = (typeStorage == TypeStorage.Arch) ?
                                    ZipFile.Open(string.Format("{0}\\backup.zip", name),
                                                 ZipArchiveMode.Update) :
                                    null;

            try
            {
                foreach (var file in resources)
                {
                    if (recoveryPoint.resources.ContainsKey(file.Key))
                    {
                        DateTime dt     = File.GetLastWriteTime(file.Key);
                        var      Myfile = Path.GetFileName(file.Key);
                        if (dt > recoveryPoint.date)
                        {
                            if (typeStorage == TypeStorage.Arch)
                            {
                                zipArchive.CreateEntryFromFile(file.Key, Myfile);
                            }
                            if (typeStorage == TypeStorage.Sep)
                            {
                                File.Copy(file.Key, string.Format("{0}\\{1}", name, Myfile));
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                return(false);
            }
            if (zipArchive != null)
            {
                zipArchive.Dispose();
            }
            return(true);
        }