示例#1
0
文件: RaiFile.cs 项目: vadgama/MLW
        /// <summary>
        /// Copy file
        /// </summary>
        /// <param name="from">can be any valid file name - no form requirements</param>
        /// <returns></returns>
        public int cp(string from)
        {
            var newname = Os.winInternal(FullName);

            rm();
            File.Copy(from, newname, true);
            #region double check if file has moved
            if (Ensure)
            {
                return(awaitFileMaterializing(newname));
            }
            #endregion
            return(0);
        }
示例#2
0
文件: RaiFile.cs 项目: vadgama/MLW
        /// <summary>
        /// throws exception if dir is not empty
        /// </summary>
        /// <param name="path"></param>
        private static void rmdir(string path)
        {
            path = Os.winInternal(path);
            var dir = new DirectoryInfo(path);

            if (dir.Exists)
            {
                Directory.Delete(path);
                if (path.ToLower().Contains("dropbox"))
                {
                    awaitDirVanishing(path);
                }
            }
        }
示例#3
0
文件: RaiFile.cs 项目: vadgama/MLW
        /// <summary>Create a directory if it does not exist yet</summary>
        /// <param name="dirname"></param>
        /// <returns>DirectoryInfo structure; contains properties Exists and CreationDate</returns>
        public static DirectoryInfo mkdir(string dirname)
        {
            dirname = Os.winInternal(string.IsNullOrEmpty(dirname) ? Directory.GetCurrentDirectory() : dirname);
            var dir = new DirectoryInfo(dirname);

            if (!dir.Exists)  // TODO problems with network drives, i.e. IservSetting.RemoteRootDir
            {
                dir = Directory.CreateDirectory(dirname);
                if (dirname.ToLower().Contains("dropbox"))
                {
                    awaitDirMaterializing(dirname);
                }
            }
            return(dir);
        }
示例#4
0
文件: RaiFile.cs 项目: vadgama/MLW
        /// <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);
        }
示例#5
0
文件: RaiFile.cs 项目: vadgama/MLW
        public int rm()                     // removes file from the file system
        {
            var name = Os.winInternal(FullName);

            if (File.Exists(name))
            {
                File.Delete(name);
                #region double check if file is gone
                if (Ensure)
                {
                    return(awaitFileVanishing(name));
                }
                #endregion
            }
            return(0);
        }
示例#6
0
文件: RaiFile.cs 项目: vadgama/MLW
        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);
        }
示例#7
0
文件: RaiFile.cs 项目: vadgama/MLW
 public static string Escape(string s, EscapeMode mode)
 {
     if (mode == EscapeMode.noEsc)
     {
         return(s);
     }
     if (mode == EscapeMode.blankEsc)
     {
         return(Os.escapeBlank(s));
     }
     if (mode == EscapeMode.paramEsc)
     {
         return(Os.escapeParam(s));
     }
     if (mode == EscapeMode.backslashed)
     {
         return(Os.winInternal(s));
     }
     return(s);
 }
示例#8
0
文件: RaiFile.cs 项目: vadgama/MLW
 /// <summary>
 /// Constructor: auto-ensure mode for file systems that do not synchronously wait for the end of an IO operation i.e. Dropbox
 /// </summary>
 /// <remarks>only use the ensure mode if it has to be guaranteed that the IO operation was completely done
 /// when the method call returns; necessary e.g. for Dropbox directories since (currently) Dropbox first updates the
 /// file in the invisible . folder and then asynchronously updates the visible file and all the remote copies of it</remarks>
 /// <param name="filename"></param>
 public RaiFile(string filename)
 {
     Ensure = filename.ToLower().Contains("dropbox");
     path   = string.Empty;
     name   = string.Empty;
     ext    = string.Empty;
     if (!string.IsNullOrEmpty(filename))
     {
         filename = filename.Replace("~", Os.HomeDir);
         filename = Os.NormSeperator(filename);
         var k = filename.LastIndexOf(Os.DIRSEPERATOR);
         if (k >= 0)
         {
             path = filename.Substring(0, k + 1);
             Name = filename.Substring(k + 1);
         }
         else
         {
             Name = filename;    // also takes care of ext
         }
     }
 }
示例#9
0
文件: RaiFile.cs 项目: vadgama/MLW
 /// <summary>
 /// Check if the file currently exists in the file system
 /// </summary>
 /// <returns></returns>
 public bool Exists()
 {
     return(File.Exists(Os.winInternal(FullName)));
 }