CClash.FileCacheStore.FileCacheStore C# (CSharp) Method

FileCacheStore() public method

public FileCacheStore ( string folderPath ) : System
folderPath string
return System
        FileCacheStore( string folderPath )
        {
            FolderPath = Path.GetFullPath(folderPath);
            mtx = new Mutex(false, "cclash_mtx_" + FolderPath.ToLower().GetHashCode());
            Logging.Emit("locking file store: {0}", FolderPath);
            WaitOne();
            
            var tlist = new List<Thread>();
            try
            {
                if (!Directory.Exists(FolderPath))
                {
                    Directory.CreateDirectory(FolderPath);
                }
                else
                {
                    bool bad_cache_format = true;
                    if (File.Exists(Path.Combine(FolderPath, CacheInfo.F_CacheVersion)))
                    {
                        var cdv = File.ReadAllText(Path.Combine(FolderPath, CacheInfo.F_CacheVersion));
                        bad_cache_format = cdv != CacheInfo.CacheFormat;
                    }

                    if (bad_cache_format)
                    {
                        Logging.Emit("corrupt filestore, deleting: {0}", FolderPath);
                        // cache is too old, wiping
                        Directory.Delete(FolderPath, true);
                        Directory.CreateDirectory(FolderPath);
                        File.WriteAllText(Path.Combine(FolderPath, CacheInfo.F_CacheVersion), CacheInfo.CacheFormat);
                    }
                }
                Logging.Emit("filestore ready: {0}", FolderPath);
            }
            catch (IOException)
            {
                throw new CClashErrorException("could not clear cache!");
            }
            catch (UnauthorizedAccessException uae)
            {
                throw new CClashWarningException("cache access error: " + uae.Message);
            }
            finally
            {
                ReleaseMutex();
            }
        }