Ejemplo n.º 1
0
        public static void Save(ICLIFlags flags, string directory, DataModels.Unlock unlock)
        {
            FindLogic.Combo.ComboInfo info = new FindLogic.Combo.ComboInfo();
            FindLogic.Combo.Find(info, unlock.GUID);

            // hmm, resaving the default spray over and over again (ref'd by SSCE) is kinda bad.

            try {
                info.Textures.First(x => x.Value.Loose).Value.Name = unlock.Name;
            } catch {
                // what
            }

            ExtractFlags extractFlags = flags as ExtractFlags;

            if (extractFlags?.SprayOnlyImage == true)
            {
                directory = Path.GetFullPath(Path.Combine(directory, ".."));
            }

            Combo.SaveLooseTextures(flags, directory, info);
            if (extractFlags?.SprayOnlyImage == true)
            {
                return;
            }
            Combo.SaveAllMaterials(flags, directory, info);
            Combo.Save(flags, directory, info);
        }
Ejemplo n.º 2
0
        private static ListFlags GetFlagsForCommand(ExtractFlags flags, string output, bool useDumpFlags = false)
        {
            if (useDumpFlags)
            {
                return new DumpFlags {
                           JSON   = true,
                           Output = $"{Path.Combine(flags.OutputPath, output)}.json"
                }
            }
            ;

            return(new ListFlags {
                JSON = true,
                Output = $"{Path.Combine(flags.OutputPath, output)}.json"
            });
        }
    }
Ejemplo n.º 3
0
        public void ExtractMOVI(ICLIFlags toolFlags)
        {
            string       basePath;
            ExtractFlags flags = toolFlags as ExtractFlags;

            basePath = flags?.OutputPath;
            if (string.IsNullOrWhiteSpace(basePath))
            {
                throw new Exception("no output path");
            }

            const string container = "DebugMovies";

            foreach (ulong key in Program.TrackedFiles[0xB6])
            {
                using (Stream videoStream = OpenFile(key)) {
                    if (videoStream != null)
                    {
                        using (BinaryReader reader = new BinaryReader(videoStream))
                        {
                            MOVI movi = reader.Read <MOVI>();
                            videoStream.Position = 128;  // wrapped in "MOVI" for some reason
                            string videoFile = Path.Combine(basePath, container, GUID.LongKey(key).ToString("X12"), $"{GUID.LongKey(key):X12}.bk2");
                            WriteFile(videoStream, videoFile);
                            FindLogic.Combo.ComboInfo audioInfo = new FindLogic.Combo.ComboInfo
                            {
                                SoundFiles = new System.Collections.Generic.Dictionary <ulong, FindLogic.Combo.SoundFileInfo>
                                {
                                    { movi.MasterAudio, new FindLogic.Combo.SoundFileInfo(movi.MasterAudio) }
                                },
                                SaveRuntimeData = new FindLogic.Combo.ComboSaveRuntimeData
                                {
                                    Threads = false
                                }
                            };
                            SaveLogic.Combo.SaveSoundFile(flags, Path.Combine(basePath, container, GUID.LongKey(key).ToString("X12")), audioInfo, movi.MasterAudio, false);
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Extract archive to disk
        /// </summary>
        /// <param name="destFolder"></param>
        /// <param name="flags"></param>
        /// <returns></returns>
        public bool Save(string destFolder, ExtractFlags[] flags = null)
        {
            if (!Directory.Exists(destFolder))
            {
                if(Directory.CreateDirectory(destFolder) == null)
                {
                    throw new Exception(string.Format("The destinition directory {0} can not be created", destFolder));
                }
            }

                bool findTrailer = false;
                _fileStream.Seek(0, SeekOrigin.Begin);

                // list all the archive entry
                List<IReaderCPIOArchiveEntry> archiveEntries = new List<IReaderCPIOArchiveEntry>();

                IReaderCPIOArchiveEntry archiveEntry = GetArchiveEntry(flags);
                int sizeBuffer = archiveEntry.EntrySize;
                byte[] buffer = new byte[sizeBuffer];

                while (_fileStream.Read(buffer, 0, sizeBuffer) == sizeBuffer)
                {
                    archiveEntry = GetArchiveEntry(flags);
                    archiveEntry.FillEntry(buffer);

                    ulong fileNameSize = archiveEntry.FileNameSize;
                    if (fileNameSize != 0)
                    {
                        byte[] fileName = new byte[fileNameSize];
                        _fileStream.Read(fileName, 0, (int)fileNameSize);
                        archiveEntry.FillFileNameData(fileName);
                    }
                    if (archiveEntry.IsLastArchiveEntry())
                    {
                        findTrailer = true;
                        break;
                    }
                    if (archiveEntry.HasData)
                    {
                        ulong dataSize = archiveEntry.DataSize;
                        byte[] data = new byte[dataSize];
                        _fileStream.Read(data, 0, (int)dataSize);
                        archiveEntry.FillDataEntry(data);
                    }

                    if (!archiveEntry.ExtractEntryToDisk(destFolder))
                    {
                        Console.WriteLine("Fail to extract the archive entry: {0}", archiveEntry.ToString());
                        Directory.Delete(destFolder, true);
                        return false;
                    }
                    archiveEntries.Add(archiveEntry);
                }
                if (!findTrailer)
                {
                    Console.WriteLine("Not find the end entry in file. File is invalid format");
                    Directory.Delete(destFolder, true);
                    return false;
                }
                else
                {
                    return PostProcessingSaveArchive(destFolder, archiveEntries);
                }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// transfrormation extract flags enum to uint
        /// </summary>
        /// <param name="flags"></param>
        /// <returns></returns>
        static protected uint GetUintFromExtractArchiveFlags(ExtractFlags[] flags)
        {
            uint exFlags = 0;
            if (flags == null)
                return exFlags;

            foreach (ExtractFlags flag in flags)
            {
                exFlags = exFlags | (uint)flag;
            }
            return exFlags;
        }
Ejemplo n.º 6
0
 /// <summary>
 /// get current reader of archive entry
 /// Fabric method
 /// </summary>
 /// <returns></returns>
 public abstract IReaderCPIOArchiveEntry GetArchiveEntry(ExtractFlags[] flags);
Ejemplo n.º 7
0
 public void ExtractPathList(int image, string target, string pathListFile, ExtractFlags extractFlags)
 {
     WimLibException.CheckWimLibError(NativeMethods.ExtractPathList(_ptr, image, target, pathListFile, extractFlags));
 }
Ejemplo n.º 8
0
 public void ExtractPaths(int image, string target, IEnumerable <string> paths, ExtractFlags extractFlags)
 {
     string[] pathArr = paths.ToArray();
     WimLibException.CheckWimLibError(NativeMethods.ExtractPaths(_ptr, image, target, pathArr, new IntPtr(pathArr.Length), extractFlags));
 }
Ejemplo n.º 9
0
 public void ExtractPath(int image, string target, string path, ExtractFlags extractFlags)
 {
     WimLibException.CheckWimLibError(NativeMethods.ExtractPaths(_ptr, image, target, new string[1] {
         path
     }, new IntPtr(1), extractFlags));
 }
Ejemplo n.º 10
0
 public void ExtractImage(int image, string target, ExtractFlags extractFlags)
 {
     WimLibException.CheckWimLibError(NativeMethods.ExtractImage(_ptr, image, target, extractFlags));
 }
Ejemplo n.º 11
0
        public bool ApplyImage(string wimFile, int imageIndex, string Output, IEnumerable <string> referenceWIMs = null, ExtractFlags extractFlags = ExtractFlags.DEFAULT, RefFlags refFlags = RefFlags.DEFAULT, ProgressCallback progressCallback = null)
        {
            string title = $"Applying {wimFile.Split('\\').Last()}...";

            try
            {
                CallbackStatus ProgressCallback(ProgressMsg msg, object info, object progctx)
                {
                    switch (msg)
                    {
                    case ProgressMsg.EXTRACT_IMAGE_BEGIN:
                    {
                        ProgressInfo_Extract m = (ProgressInfo_Extract)info;
                    }
                    break;

                    case ProgressMsg.EXTRACT_IMAGE_END:
                    {
                        ProgressInfo_Extract m = (ProgressInfo_Extract)info;
                    }
                    break;

                    case ProgressMsg.EXTRACT_FILE_STRUCTURE:
                    {
                        ProgressInfo_Extract m = (ProgressInfo_Extract)info;
                        progressCallback?.Invoke($"Applying file structure ({(int)Math.Round((double)m.CurrentFileCount / m.EndFileCount * 100)}%)", 0, true);
                    }
                    break;

                    case ProgressMsg.EXTRACT_STREAMS:
                    {
                        ProgressInfo_Extract m = (ProgressInfo_Extract)info;
                        progressCallback?.Invoke(title, (int)Math.Round((double)m.CompletedBytes / m.TotalBytes * 100), false);
                    }
                    break;

                    case ProgressMsg.EXTRACT_METADATA:
                    {
                        ProgressInfo_Extract m = (ProgressInfo_Extract)info;
                        progressCallback?.Invoke($"Applying metadata ({(int)Math.Round((double)m.CompletedBytes / m.TotalBytes * 100)}%)", 0, true);
                    }
                    break;
                    }
                    return(CallbackStatus.CONTINUE);
                }

                using (Wim wim = Wim.OpenWim(wimFile, OpenFlags.DEFAULT))
                {
                    wim.RegisterCallback(ProgressCallback);
                    if (referenceWIMs != null && referenceWIMs.Count() > 0)
                    {
                        wim.ReferenceResourceFiles(referenceWIMs, (ManagedWimLib.RefFlags)refFlags, OpenFlags.DEFAULT);
                    }
                    wim.ExtractImage(imageIndex, Output, (ManagedWimLib.ExtractFlags)extractFlags);
                }
            }
            catch
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 12
0
 public override IReaderCPIOArchiveEntry GetArchiveEntry(ExtractFlags[] flags)
 {
     return new ODCReaderArchiveEntry(GetUintFromExtractArchiveFlags(flags));
 }
Ejemplo n.º 13
0
 public override IReaderCPIOArchiveEntry GetArchiveEntry(ExtractFlags[] flags)
 {
     return new NewASCIIReaderFormatArchiveEntry(GetUintFromExtractArchiveFlags(flags));
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Extract archive to disk
 /// </summary>
 /// <param name="destFolder">Destinition folder</param>
 /// <param name="flags">Optional flags for additional behaviour</param>
 /// <returns></returns>
 public bool Extract(string destFolder, ExtractFlags[] flags = null)
 {
     return _currentCpioFileStream.Save(destFolder, flags);
 }