Beispiel #1
0
 /// <summary>
 /// usees 7zip
 /// </summary>
 /// <returns>zipArchive as RsbFile or null</returns>
 // public RaiFile Zip7()
 // {
 //     var zip7 = new RaiFile(FullName + ".7z");
 //     zip7.rm();  // remove it if an old version exists
 //                 //var oldCurrentDir = Directory.GetCurrentDirectory();
 //                 //Directory.SetCurrentDirectory("c:\\Program Files\\7-Zip\\");
 //     var call = new RaiSystem("7z", "a -mmt " + Os.escapeParam(zip7.FullName) + " " + Os.escapeParam(FullName));
 //     call.Exec();
 //     //Directory.SetCurrentDirectory(oldCurrentDir);
 //     if (call.ExitCode == 0 && zip7.Exists())
 //     {
 //         rm();
 //         return zip7;
 //     }
 //     return null;
 // }
 /// <summary>
 /// usees 7zip with options -t7z -m0=lzma2 -mx=9 -aoa
 /// </summary>
 /// <returns>zipArchive as RsbFile or null</returns>
 // public RaiFile ZipUltra()
 // {
 //     var zip7 = new RaiFile(FullName + ".7z");
 //     zip7.rm();  // remove it if an old version exists
 //                 //var oldCurrentDir = Directory.GetCurrentDirectory();
 //                 //Directory.SetCurrentDirectory("c:\\Program Files\\7-Zip\\");
 //     var call = new RaiSystem("7z", "a -t7z -m0=lzma2 -mx=9 -aoa " + Os.escapeParam(zip7.FullName) + " " + Os.escapeParam(FullName));
 //     call.Exec();
 //     //Directory.SetCurrentDirectory(oldCurrentDir);
 //     if (call.ExitCode == 0 && zip7.Exists())
 //     {
 //         rm();
 //         return zip7;
 //     }
 //     return null;
 // }
 /// <summary>
 /// unzip an 7z archive using 7z commandline
 /// </summary>
 /// <returns>and RsbFile - use the Path to identify where the taget file(s) are located</returns>
 // public RaiFile UnZip7()
 // {
 //     var unzipped = new RaiFile(FullName.Substring(0, FullName.IndexOf(".7z")));
 //     var call = new RaiSystem("7z", "e " + Os.escapeParam(FullName) + " -o" + unzipped.Path);
 //     call.Exec();
 //     // do not remove 7z file
 //     return unzipped;
 // }
 /// <summary>
 /// copies the file on disk identified by the current RsbFile object to multiple destinations
 /// </summary>
 /// <param name="destDirs"></param>
 /// <returns></returns>
 public bool CopyTo(string[] destDirs)
 {
     try
     {
         RaiFile dest;
         string  destName;
         foreach (var destDir in destDirs)
         {
             dest = new RaiFile(FullName)
             {
                 Path = destDir
             };
             destName = dest.FullName;
             dest.mkdir();
             if (File.Exists(destName))
             {
                 File.Delete(destName);
             }
             File.Copy(FullName, destName);
         }
     }
     catch (Exception)
     {
         return(false);
     }
     return(true);
 }
Beispiel #2
0
        /// <summary>
        /// Copy file
        /// </summary>
        /// <param name="from">will be checked; exception will be thrown if file name does not match RsbFile form requirements</param>
        /// <returns>0 if everything went well</returns>
        public int cp(RaiFile from)
        { // copy file in the file system
            var oldname = Os.winInternal(from.FullName);
            var newname = Os.winInternal(FullName);

            rm();                              // make sure it's really gone before we go ahead; applies ensure
            File.Copy(oldname, newname, true); // overwrite if exists (which should never happen since we just removed it)
            #region double check if file has moved
            if (Ensure)
            {
                return(awaitFileMaterializing(newname));
            }
            #endregion
            return(0);
        }
Beispiel #3
0
        public int mv(RaiFile from)         // relocates file in the file system
        {
            //bool destIsDropbox = Name.ToLower().Contains("dropbox");
            //bool srcIsDropbox = from.Name.ToLower().Contains("dropbox");
            //#region both files in Dropbox - no acceleration
            //#endregion
            mkdir(); // create destdir if necessary; applies ensure
            var newname = Os.winInternal(FullName);
            var oldname = Os.winInternal(from.FullName);

            rm();                        // make sure it's really gone before we go ahead; applies ensure
            File.Move(oldname, newname); // make sure the user that w3wp runs under has write/delete access to oldname, i.e. c:\dropbox\config\3.3.3\Users.xml
            #region double check if file has moved
            if (Ensure)
            {
                return(awaitFileVanishing(oldname) + awaitFileMaterializing(newname));
            }
            #endregion
            return(0);
        }
Beispiel #4
0
        /// <summary>
        /// zip this file into archive
        /// </summary>
        /// <returns>the archive name</returns>
        public RaiFile Zip()
        {
            var inFolder = new RaiFile(this.FullName);
            var file     = new RaiFile(this.FullName);

            inFolder.Name = file.Name;
            inFolder.Path = inFolder.Path + inFolder.Name;
            inFolder.mv(file);
            file.Ext = file.Ext + ".zip";
            File.Delete(file.FullName);   // delete any pre-existing file
            try
            {
                ZipFile.CreateFromDirectory(inFolder.Path, file.FullName);
                //ZipFile.
            }
            catch (Exception)
            {
                return(null);
            }
            return(file);
        }
Beispiel #5
0
        /// <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);
        }