Пример #1
0
        private bool HandleGameFileIWad(IGameFile gameFile, ISourcePort sourcePort, StringBuilder sb, LauncherPath gameFileDirectory, LauncherPath tempDirectory)
        {
            try
            {
                using (IArchiveReader reader = ArchiveReader.Create(Path.Combine(gameFileDirectory.GetFullPath(), gameFile.FileName)))
                {
                    IArchiveEntry entry       = reader.Entries.First();
                    string        extractFile = Path.Combine(tempDirectory.GetFullPath(), entry.Name);
                    if (ExtractFiles && entry.ExtractRequired)
                    {
                        entry.ExtractToFile(extractFile, true);
                    }

                    if (!entry.ExtractRequired)
                    {
                        extractFile = entry.FullName;
                    }

                    sb.Append(sourcePort.IwadParameter(new SpData(extractFile, gameFile, AdditionalFiles)));
                }
            }
            catch (FileNotFoundException)
            {
                LastError = string.Format("File not found: {0}", gameFile.FileName);
                return(false);
            }
            catch (IOException)
            {
                LastError = string.Format("File in use: {0}", gameFile.FileName);
                return(false);
            }
            catch (Exception)
            {
                LastError = string.Format("There was an issue with the IWad: {0}. Corrupted file?", gameFile.FileName);
                return(false);
            }

            return(true);
        }
Пример #2
0
        //Takes a file 'MAP01.wad' and makes it 'MAP01_GUID.wad'.
        //Checks if file with prefix MAP01 exists with same file length and returns that file (same file).
        //Otherwise a new file is extracted and returned.
        public static string ExtractTempFile(string tempDirectory, IArchiveEntry entry)
        {
            // The file is a regular file and not an archive - return the FulName
            if (!entry.ExtractRequired)
            {
                return(entry.FullName);
            }

            string ext  = Path.GetExtension(entry.Name);
            string file = entry.Name.Replace(ext, string.Empty) + "_";

            string[] searchFiles = Directory.GetFiles(tempDirectory, file + "*");

            string matchingFile = searchFiles.FirstOrDefault(x => new FileInfo(x).Length == entry.Length);

            if (matchingFile == null)
            {
                string extractFile = Path.Combine(tempDirectory, string.Concat(file, Guid.NewGuid().ToString(), ext));
                entry.ExtractToFile(extractFile);
                return(extractFile);
            }

            return(matchingFile);
        }