Пример #1
0
        public DownloadHandle(
            string name,
            string downloadPath,
            ref FileHash hash,
            Loader.OnError onError,
            int retryCount,
            int timeoutSeconds,
            System.Action <int> onProgress,
            StorageCache storageCache,
            FileWriter fileWriter)
        {
            Debug.Assert(name != null);
            Debug.Assert(downloadPath != null);
            Debug.Assert(onError != null);
            Debug.Assert(storageCache != null);
            Debug.Assert(fileWriter != null);

            this.name       = name;
            _onError        = onError;
            _downloadPath   = downloadPath;
            _hash           = hash;
            _restRetryCount = retryCount;
            _timeoutSeconds = timeoutSeconds;
            _onProgress     = onProgress;
            _storageCache   = storageCache;
            _fileWriter     = fileWriter;
        }
Пример #2
0
        public static void Clear(string root, Dictionary <string, StorageCache.Entry> entries)
        {
            var stringBuilder = new System.Text.StringBuilder();

            // ファイル個別削除
            foreach (var item in entries)
            {
                var entry     = item.Value;
                var cachePath = StorageCache.MakeCachePath(stringBuilder, item.Key, ref entry.hash, root);
                FileUtility.DeleteFile(cachePath);
            }
            FileUtility.RemoveEmptyDirectories(root);
        }
Пример #3
0
        void BuildRecursive(string path)         // 別スレッド実行
        {
            var dirs = Directory.GetDirectories(path);

            foreach (var dir in dirs)
            {
                BuildRecursive(dir);
            }
            var files = Directory.GetFiles(path);

            foreach (var file in files)
            {
                StorageCache.Entry newEntry;
                string             name;
                bool isTemporary;
                if (!ParseCachePath(out name, out newEntry.hash, out isTemporary, file))
                {
                    // 認識できないファイルなので無視。誰かが置いたのだろう。
                }
                else if (isTemporary)                 // 書き込み中が見つかれば問答無用で削除
                {
                    FileUtility.DeleteFile(file);
                }
                else
                {
                    lock (_entries)
                    {
                        StorageCache.Entry oldEntry;
                        if (_entries.TryGetValue(name, out oldEntry))                         // すでに辞書に入ってる。バグによるものと思われ、判断がつかないので両方消す。
                        {
                            FileUtility.DeleteFile(file);
                            _stringBuilder.Length = 0;
                            StorageCache.MakeCachePath(_stringBuilder, name, ref oldEntry.hash, _root, _useHash);
                            FileUtility.DeleteFile(_stringBuilder.ToString());
                        }
                        else
                        {
                            _entries.Add(name, newEntry);
                        }
                    }
                }
            }
        }