Esempio n. 1
0
        public static FSFileInfo GetFileInfo(string fileName, bool addToDownloadList = false)
        {
            FSFileInfo result = null;

            var isFullPath   = fileName.IndexOfAny(_slashes) != -1;
            var isWorkshopId = ulong.TryParse(fileName, out ulong workshopId);

            foreach (var provider in FileProviders)
            {
                foreach (var file in provider.Files)
                {
                    if ((isFullPath && PathsAreEqual(file.Value.FullPath, fileName)) ||
                        (!isFullPath && string.Equals(fileName, file.Value.NameWithExtension, StringComparison.InvariantCultureIgnoreCase)) ||
                        (isWorkshopId && file.Value.WorkshopId == workshopId))
                    {
                        result = file.Value;
                        break;
                    }
                }
            }

            if (result != null && addToDownloadList)
            {
                DownloadList.Add(result);
            }

            return(result);
        }
Esempio n. 2
0
        public FSFileInfo GetFile(string path)
        {
            path = path.ToLower();

            FSFileInfo result = null;

            if (Files.ContainsKey(path))
            {
                result = Files[path];
            }
            else
            {
                foreach (var kvp in Files)
                {
                    if (kvp.Key.EndsWith(path))
                    {
                        result = kvp.Value;
                    }
                }
            }

            if (result != null && result.Hash == null)
            {
                CreateMD5(result);
            }

            return(result);
        }
Esempio n. 3
0
        public async Task BuildAsync()
        {
            if (!SteamClient.IsValid)
            {
                return;
            }

            var query  = Query.All.WhereUserSubscribed();
            var result = await query.GetPageAsync(1);

            if (result.HasValue)
            {
                Files.Clear();
                foreach (var item in result.Value.Entries)
                {
                    if (!Directory.Exists(item.Directory))
                    {
                        continue;
                    }
                    var files = Directory.GetFiles(item.Directory, "*.fsm").Union(Directory.GetFiles(item.Directory, "*.rfsm"));
                    if (files != null && files.Count() > 0)
                    {
                        var fileInfo = new FSFileInfo(files.ElementAt(0), Path.GetFileName(files.ElementAt(0)));
                        if (Files.ContainsKey(fileInfo.RelativePath))
                        {
                            continue;
                        }
                        fileInfo.WorkshopId = item.Id;
                        Files.Add(fileInfo.RelativePath, fileInfo);
                    }
                }
                result.Value.Dispose();
            }
        }
Esempio n. 4
0
 private void CreateMD5(FSFileInfo file)
 {
     using (var md5 = MD5.Create())
     {
         using (var fs = File.OpenRead(file.FullPath))
         {
             file.Hash   = md5.ComputeHash(fs);
             file.Length = fs.Length;
         }
     }
 }
Esempio n. 5
0
        public async Task <TransferStatus> UploadFileAsync(IPlayer player, FSFileInfo file, bool temporaryFile)
        {
            var upload = new UploadState(file);

            upload.Status          = TransferStatus.InProgress;
            upload.IsTemporaryFile = temporaryFile;
            while (upload.Status == TransferStatus.InProgress)
            {
                if (player.Disconnected)
                {
                    upload.Status = TransferStatus.Failed;
                    break;
                }
                SendChunk(player, upload);
                await Task.Delay(100);
            }

            return(upload.Status);
        }
Esempio n. 6
0
        private void ScanDirectory(DirToScan dir)
        {
            // get all files except those dirty .meta files when in editor
            var allFiles = Directory.GetFiles(dir.Path, dir.SearchPattern, SearchOption.AllDirectories)
                           .ToList()
                           .FindAll(x => !x.EndsWith(".meta", StringComparison.InvariantCultureIgnoreCase));

            dir.Path = dir.Path.Replace('/', '\\').ToLower();

            foreach (var fullPath in allFiles)
            {
                var normalizedPath = fullPath.Replace('/', '\\').ToLower();
                var relativePath   = normalizedPath.Replace(dir.Path, "");
                var fileInfo       = new FSFileInfo(fullPath, relativePath);
                if (Files.ContainsKey(fileInfo.RelativePath))
                {
                    continue;
                }
                Files.Add(fileInfo.RelativePath, fileInfo);
            }
        }
Esempio n. 7
0
        private IFragsurfMap GetMapLoader(string path)
        {
            if (path == "LoadActiveScene")
            {
                return(new ActiveSceneMap());
            }

            FSFileInfo fileInfo = null;

            if (!Path.HasExtension(path) && !ulong.TryParse(path, out ulong workshopId))
            {
                foreach (var ext in _validExtensions)
                {
                    fileInfo = FileSystem.GetOrAcquire($"{path}.{ext}", true);
                    if (fileInfo != null)
                    {
                        break;
                    }
                }
            }
            else
            {
                fileInfo = FileSystem.GetOrAcquire(path, true);
            }

            if (fileInfo == null)
            {
                return(null);
            }

            switch (fileInfo.Extension)
            {
            default:
                return(null);
            }
        }
Esempio n. 8
0
 public static FileCheck CheckFile(FSFileInfo file)
 {
     return(CheckFile(file.RelativePath, file.Hash));
 }
Esempio n. 9
0
 public UploadState(FSFileInfo file)
 {
     File        = file;
     InputStream = new FileStream(file.FullPath, FileMode.Open, FileAccess.Read);
 }