예제 #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
        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);
        }