示例#1
0
文件: RaiFile.cs 项目: vadgama/MLW
        /// <summary>create a backup file</summary>
        /// <param name="copy">moves if false, copies otherwise</param>
        /// <returns>name of backupfile, if there was one created</returns>
        /// <remarks>the Os.LocalBackupDir will be used; make sure it's not in the Dropbox</remarks>
        public string backup(bool copy = false)
        {
            if (!File.Exists(FullName))
            {
                return(null);   // no file no backup
            }
            var backupFile = new RaiFile(FullName);
            var idx        = (backupFile.Path.Length > 2 && backupFile.Path[1] == ':') ? 3 : 0; // works as expected for c:/123 or c:\123, but not for c:123
            var s          = backupFile.Path.Substring(idx);

            backupFile.Path = (Os.LocalBackupDir + s).Replace("Dropbox/", "").Replace("dropbox/", "");   // eliminates Dropbox for LocalBackupDir to avoid ensure
            mkdir(backupFile.Path);
            backupFile.Name = backupFile.Name + " " + DateTimeOffset.UtcNow.ToString(Os.DATEFORMAT);
            backupFile.Ext  = Ext;
            if (copy)
            {
                backupFile.cp(this);
            }
            else
            {
                backupFile.mv(this);
            }
            return(backupFile.FullName);
        }