Пример #1
0
        static string GetDirFileString(int level, System.IO.FileSystemInfo dirfile)
        {
            //char l0 = '+'; Пробовал с символами псвдографики, без них понравилось больше
            //char l1 = '\u251C';// ├
            //char l2 = '\u2500';// ─
            //char l02 = '\u2502';// │
            //char l3 = '\u2514'; //└
            string indent         = level == 0 ? "" : "  ";
            char   horizLine      = Properties.Settings.Default.HorizLines ? '-' : ' ';
            int    mode           = Properties.Settings.Default.ViewMode;
            int    maxFileNameLen = Const.GetMaxFileNameLen(mode);
            string s = indent + dirfile.Name;

            if (s.Length > maxFileNameLen)
            {
                s = s.Substring(0, maxFileNameLen - 3) + Str.tooLongString; //если длина строки больше ширины колонки
            }
            s = s.PadRight(maxFileNameLen, horizLine);                      //колонка 1
            if (mode > 0)
            {
                string s1;
                if (dirfile.GetType() == typeof(System.IO.FileInfo))
                {
                    System.IO.FileInfo f = (System.IO.FileInfo)dirfile;
                    s1 = Str.GetSizeString(f.Length);
                }
                else
                {
                    s1 = Str.directory;
                }
                s1 = s1.PadRight(Const.sizeStringLen); //колонка 2
                s += s1;
            }
            if (mode > 1)
            {
                string s1 = Str.GetFileAttributesString(dirfile.Attributes);
                s1 = s1.PadRight(Const.attrStringLen); //колонка 3
                s += s1;
            }
            if (mode > 2)
            {
                string s1 = dirfile.CreationTime.ToString(Str.dateTimePatt);
                s1 = s1.PadRight(Const.timeStringLen); //колонка 4
                s += s1;
            }
            if (mode > 3)
            {
                string s1 = dirfile.LastAccessTime.ToString(Str.dateTimePatt);
                s1 = s1.PadRight(Const.timeStringLen); //колонка 5
                s += s1;
            }
            if (mode > 4)
            {
                string s1 = dirfile.LastWriteTime.ToString(Str.dateTimePatt);
                s1 = s1.PadRight(Const.timeStringLen); //колонка 6
                s += s1;
            }
            return(s);
        }
Пример #2
0
        public static long GetSize(FileSystemInfo fsi)
        {
            Exceptions.CheckArgumentNull(fsi, "fsi");

            try
            {
                FileInfo fileInfo = fsi as FileInfo;
                if (fileInfo != null)
                    return fileInfo.Length;

                DirectoryInfo directoryInfo = fsi as DirectoryInfo;
                if (directoryInfo != null)
                    return directoryInfo.EnumerateFiles("*", SearchOption.AllDirectories).Sum(f => f.Length);

                Log.Warning("[FileEx]Неизвестный наследник FileSystemInfo: {0}", fsi.GetType());
                return 0;
            }
            catch (Exception ex)
            {
                Log.Warning(ex, "[FileEx]Непредвиденная ошибка.");
                return 0;
            }
        }
Пример #3
0
        /// <summary>
        /// Uploads the specified file or directory to the remote host.
        /// </summary>
        /// <param name="fileInfo">Local file to upload.</param>
        /// <param name="filename">Remote host file name.</param>
        /// <exception cref="ArgumentNullException"><paramref name="fileInfo"/> or <paramref name="filename"/> is null.</exception>
        public void Upload(FileSystemInfo fileSystemInfo, string path)
        {
            if (fileSystemInfo == null)
                throw new ArgumentNullException("fileSystemInfo");

            if (string.IsNullOrEmpty(path))
                throw new ArgumentException("path");

            using (var input = new PipeStream())
            using (var channel = this.Session.CreateChannel<ChannelSession>())
            {
                channel.DataReceived += delegate(object sender, Common.ChannelDataEventArgs e)
                {
                    input.Write(e.Data, 0, e.Data.Length);
                    input.Flush();
                };

                channel.Open();

                var pathParts = path.Split('\\', '/');

                //  Send channel command request
                channel.SendExecRequest(string.Format("scp -rt \"{0}\"", pathParts[0]));
                this.CheckReturnCode(input);

                //  Prepare directory structure
                for (int i = 0; i < pathParts.Length - 1; i++)
                {
                    this.InternalSetTimestamp(channel, input, fileSystemInfo.LastWriteTimeUtc, fileSystemInfo.LastAccessTimeUtc);
                    this.SendData(channel, string.Format("D0755 0 {0}\n", pathParts[i]));
                    this.CheckReturnCode(input);
                }

                if (fileSystemInfo is FileInfo)
                {
                    this.InternalUpload(channel, input, fileSystemInfo as FileInfo, pathParts.Last());
                }
                else if (fileSystemInfo is DirectoryInfo)
                {
                    this.InternalUpload(channel, input, fileSystemInfo as DirectoryInfo, pathParts.Last());
                }
                else
                {
                    throw new NotSupportedException(string.Format("Type '{0}' is not supported.", fileSystemInfo.GetType().FullName));
                }

                //  Finish directory structure
                for (int i = 0; i < pathParts.Length - 1; i++)
                {
                    this.SendData(channel, "E\n");
                    this.CheckReturnCode(input);
                }

                channel.Close();
            }
        }
Пример #4
0
        /// <summary>
        /// Get image key for given folder of file
        /// </summary>
        /// <param name="info">FileInfo for a file or DirectoryInfo for directory</param>
        /// <returns>Image keys from imagelist1</returns>
        private string GetKey(FileSystemInfo info)
        {
            string key = info.Name.ToLower();
            try { if (imageList1.Images.ContainsKey(key)) return key; }
            catch { }

            key = info.Extension.ToLower();
            try { if (imageList1.Images.ContainsKey(key)) return key; }
            catch { }

            if (info.GetType() == typeof(FileInfo)) return "file";

            string name = info.FullName.Substring(RegistryAccess.CodesPath.Length + 1);
            if (!name.StartsWith("Volume"))
            {
                if (name.Contains(Path.DirectorySeparatorChar.ToString())) return key = "folder";
                return "root";
            }

            if (name.Contains(Path.DirectorySeparatorChar.ToString())) return "problem";
            return "volume";
        }
		/// <summary>
		/// Scan a FileSystem object (file or directory) with optional recursion.
		/// </summary>
		/// <param name="file">FileSystem object to scan</param>
		/// <param name="recurse">Recurse when true if FileSystem object is a directory. Otherwise this argument is ignored..</param>
		public override void Scan(FileSystemInfo file, bool recurse)
		{
			if( file!=null) 
			{
				if(file is FileInfo)
					Scan(file as FileInfo);
				else if (file is DirectoryInfo)
					Scan(file as DirectoryInfo, recurse);
				else
					throw new NotSupportedException( string.Format(  CultureInfo.CurrentCulture, ResourceManagers.Strings.GetString(STR_SCAN_FILESYSTEMINFO_NONT_SUPPORTED), file.GetType() ) );
			}
		}
Пример #6
0
        /// <summary>
        /// Checks the end of a path string, if the path ends in CVS it does nothing, 
        /// otherwise it appends CVS to the full path.
        /// </summary>
        /// <param name="fs">Full path to a file/ directory that may or may
        ///     not end with CVS.</param>
        /// <returns>The full path with a CVS appended.</returns>
        public static FileSystemInfo AppendCvs(FileSystemInfo fs) {
            if (fs.FullName.EndsWith(string.Format("{0}{1}{2}", Path.DirectorySeparatorChar, CVS, Path.DirectorySeparatorChar)) ||
                fs.FullName.EndsWith(string.Format("{0}{1}", Path.DirectorySeparatorChar, CVS)) ||
                PathTranslator.IsCvsDir(fs.FullName)) {
                LOGGER.Warn(string.Format("Already ends with cvs directory: {0}",
                    fs.FullName));
                return fs;
            } 

            if (fs.GetType() == typeof(DirectoryInfo)) {
                return new DirectoryInfo(Path.Combine(fs.FullName, CVS));
            } else {
                return new FileInfo(Path.Combine(fs.FullName, CVS));
            }
        }