示例#1
0
        public static void CleanEmptyDirectories(System.IO.FileInfo target)
        {
            var dir = target.Directory;

            try
            {
                for (var i = 0; i < PathHelper.Depth && dir.Exists; i++)
                {
                    dir.Delete();
                    dir = dir.Parent;
                }
            }
            catch
            {
            }
        }
示例#2
0
        public static FileInfo GetFileInfo(string id, string path = null)
        {
            if (!CryptoHelper.IsHashValid(id))
            {
                return(null);
            }
            if (path == null)
            {
                path = PathHelper.MapLocal(id, Config.Dfs.Path);
            }
            var f = new System.IO.FileInfo(path);

            if (!f.Exists)
            {
                return(null);
            }
            var ret = new FileInfo(id, f.Length, f.CreationTime, f.LastAccessTime);

            UpdateLastAccessed(f.FullName);
            return(ret);
        }
示例#3
0
        public static string PutLocal(string filename, string s64Sha256 = null, bool move = false)
        {
            var key = s64Sha256;

            if (key == null)
            {
                using (var fs = File.Open(filename, FileMode.Open, FileAccess.Read, System.IO.FileShare.Read))
                {
                    key = fs.S64Sha256L();
                }
            }

            if (FileExists(key))
            {
                if (move)
                {
                    try
                    {
                        File.Delete(filename);
                    }
                    catch
                    {
                    }
                }
                return(key);
            }

            var f = new System.IO.FileInfo(PathHelper.MapLocal(key, Config.Dfs.Path));

            f.Directory.Create();
            if (move)
            {
                File.Move(filename, f.FullName);
            }
            else
            {
                File.Copy(filename, f.FullName, false);
            }
            return(key);
        }
示例#4
0
        public static bool Delete(string id)
        {
            if (!CryptoHelper.IsHashValid(id))
            {
                return(false);
            }
            if (!FileExists(id, out var path))
            {
                return(true);
            }
            var ret = false;

            try
            {
                var fi = new System.IO.FileInfo(path);
                fi.Delete();
                ret = true;
                CleanEmptyDirectories(fi);
            }
            catch
            {
            }
            return(ret);
        }