Example #1
0
        private string extractIros(string iroFile, string path)
        {
            bPreview.Enabled = false;
            _7thWrapperLib.IrosArc iro = new _7thWrapperLib.IrosArc(iroFile);
            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            string filter = path;
            string fn     = "";

            foreach (string file in iro.AllFileNames())
            {
                if (!String.IsNullOrEmpty(filter) && (file.IndexOf(filter) < 0))
                {
                    continue;
                }
                byte[] data = iro.GetBytes(file);
                fn = System.IO.Path.Combine(System.IO.Path.GetTempPath(), file);
                System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(fn));
                System.IO.File.WriteAllBytes(fn, data);
            }
            sw.Stop();
            bPreview.Enabled = true;
            return(fn);
        }
Example #2
0
        void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            IroOp            io = e.Argument as IroOp;
            BackgroundWorker bw = sender as BackgroundWorker;

            using (var arc = new _7thWrapperLib.IrosArc(io.Iro)) {
                var files = arc.AllFileNames().ToList();
                int count = 0;
                foreach (string file in files)
                {
                    string path = System.IO.Path.Combine(io.Folder, file);
                    System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(path));
                    System.IO.File.WriteAllBytes(path, arc.GetBytes(file));
                    count++;
                    IroProgress(1.0 * count / files.Count, file);
                }
            }
        }
Example #3
0
        internal Task UnpackIro()
        {
            string pathToOutput = PathToOutputFolder;
            string pathToIro    = PathToIroFile;

            IsUnpacking = true;

            Task unpackTask = Task.Factory.StartNew(() =>
            {
                using (_7thWrapperLib.IrosArc arc = new _7thWrapperLib.IrosArc(pathToIro))
                {
                    List <string> files = arc.AllFileNames().ToList();
                    int count           = 0;
                    foreach (string file in files)
                    {
                        string path = Path.Combine(pathToOutput, file);

                        Directory.CreateDirectory(Path.GetDirectoryName(path));
                        File.WriteAllBytes(path, arc.GetBytes(file));

                        count++;
                        IroProgress(1.0 * count / files.Count, file);
                    }
                }
            });

            unpackTask.ContinueWith((result) =>
            {
                IsUnpacking   = false;
                ProgressValue = 0;

                if (result.IsFaulted)
                {
                    Logger.Warn(result.Exception.GetBaseException());
                    StatusText = $"An error occured while unpacking: {result.Exception.GetBaseException().Message}";
                    return;
                }

                StatusText = "Unpacking complete!";
            });

            return(unpackTask);
        }
Example #4
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                System.Console.WriteLine(HELP);
                return;
            }
            _7thWrapperLib.RuntimeLog.Enabled = args.Any(s => s.Equals("/LOG", StringComparison.InvariantCultureIgnoreCase));

            Action <double, string> onProgress = (d, s) => {
                Console.WriteLine(String.Format("{0}%: {1}", (int)(d * 100), s));
            };

            if (args[0].Equals("LIST", StringComparison.InvariantCultureIgnoreCase))
            {
                _7thWrapperLib.IrosArc iro = new _7thWrapperLib.IrosArc(args[1]);
                foreach (string s in iro.GetInformation())
                {
                    Console.WriteLine(s);
                }
            }
            else if (args[0].Equals("CREATE", StringComparison.InvariantCultureIgnoreCase))
            {
                List <_7thWrapperLib.IrosArc.ArchiveCreateEntry> entries = new List <_7thWrapperLib.IrosArc.ArchiveCreateEntry>();
                string dir = args[2];
                foreach (string file in System.IO.Directory.GetFiles(dir, "*", System.IO.SearchOption.AllDirectories))
                {
                    entries.Add(_7thWrapperLib.IrosArc.ArchiveCreateEntry.FromDisk(dir, file.Substring(dir.Length).Trim('/', '\\')));
                }
                _7thWrapperLib.CompressType compress = (_7thWrapperLib.CompressType)Enum.Parse(typeof(_7thWrapperLib.CompressType), args[3]);

                using (var fs = new System.IO.FileStream(args[1], System.IO.FileMode.Create))
                    _7thWrapperLib.IrosArc.Create(fs,
                                                  entries,
                                                  _7thWrapperLib.ArchiveFlags.None,
                                                  compress,
                                                  onProgress
                                                  );
            }
            else if (args[0].Equals("EXTRACT", StringComparison.InvariantCultureIgnoreCase))
            {
                _7thWrapperLib.IrosArc iro = new _7thWrapperLib.IrosArc(args[1]);
                var sw = new System.Diagnostics.Stopwatch();
                sw.Start();
                string filter = args.Length > 3 ? args[3] : String.Empty;
                foreach (string file in iro.AllFileNames())
                {
                    if (!String.IsNullOrEmpty(filter) && (file.IndexOf(filter) < 0))
                    {
                        continue;
                    }
                    Console.WriteLine("Writing " + file);
                    byte[] data = iro.GetBytes(file);
                    string fn   = System.IO.Path.Combine(args[2], file);
                    fn = fn.Replace("%", "___").Replace(":", "---");
                    System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(fn));
                    System.IO.File.WriteAllBytes(fn, data);
                }
                sw.Stop();
                Console.WriteLine("Done in " + (sw.ElapsedMilliseconds / 1000f) + " seconds");
            }
            else if (args[0].Equals("MAKEPATCH", StringComparison.InvariantCultureIgnoreCase))
            {
                _7thWrapperLib.IrosArc      orig     = new _7thWrapperLib.IrosArc(args[1]);
                _7thWrapperLib.IrosArc      newarc   = new _7thWrapperLib.IrosArc(args[2]);
                _7thWrapperLib.CompressType compress = (_7thWrapperLib.CompressType)Enum.Parse(typeof(_7thWrapperLib.CompressType), args[4]);
                using (var fs = new System.IO.FileStream(args[3], System.IO.FileMode.Create)) {
                    _7thWrapperLib.IrosPatcher.Create(orig, newarc, fs, compress, onProgress);
                }
            }
            else if (args[0].Equals("APPLYPATCH", StringComparison.InvariantCultureIgnoreCase))
            {
                _7thWrapperLib.IrosArc orig  = new _7thWrapperLib.IrosArc(args[1], true);
                _7thWrapperLib.IrosArc patch = new _7thWrapperLib.IrosArc(args[2]);
                orig.ApplyPatch(patch, onProgress);
            }
        }
Example #5
0
        public static void ImportMod(string source, string name, bool iroMode, bool noCopy)
        {
            Mod m = new Mod()
            {
                Author        = String.Empty,
                Description   = "Imported mod",
                ID            = Guid.NewGuid(),
                Link          = String.Empty,
                Tags          = new List <string>(),
                Name          = name,
                LatestVersion = new ModVersion()
                {
                    CompatibleGameVersions = GameVersions.All,
                    Links        = new List <string>(),
                    PreviewImage = String.Empty,
                    ReleaseDate  = DateTime.Now,
                    ReleaseNotes = String.Empty,
                    Version      = 1.00m,
                }
            };

            string location;

            if (noCopy)
            {
                location = System.IO.Path.GetFileName(source);
            }
            else
            {
                location = String.Format("{0}_{1}", m.ID, name);
            }
            System.Xml.XmlDocument doc     = null;
            Func <string, byte[]>  getData = null;

            if (!iroMode)
            {
                if (!noCopy)
                {
                    foreach (string file in System.IO.Directory.GetFiles(source, "*", System.IO.SearchOption.AllDirectories))
                    {
                        string part = file.Substring(source.Length).Trim('\\', '/');
                        string dest = System.IO.Path.Combine(Sys.Settings.LibraryLocation, location, part);
                        System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(dest));
                        System.IO.File.Copy(file, dest, true);
                    }
                }
                string mx = System.IO.Path.Combine(Sys.Settings.LibraryLocation, location, "mod.xml");
                if (System.IO.File.Exists(mx))
                {
                    doc = new System.Xml.XmlDocument();
                    doc.Load(mx);
                }
                getData = s => {
                    string file = System.IO.Path.Combine(Sys.Settings.LibraryLocation, location, s);
                    if (System.IO.File.Exists(file))
                    {
                        return(System.IO.File.ReadAllBytes(file));
                    }
                    return(null);
                };
                //System.IO.Directory.Move(txtFolder.Text, System.IO.Path.Combine(Sys.Settings.LibraryLocation, location));
            }
            else
            {
                if (!noCopy)
                {
                    location = location + ".iro";
                    System.IO.File.Copy(source, System.IO.Path.Combine(Sys.Settings.LibraryLocation, location), true);
                }
                var arc = new _7thWrapperLib.IrosArc(source);
                if (arc.HasFile("mod.xml"))
                {
                    doc = new System.Xml.XmlDocument();
                    doc.Load(arc.GetData("mod.xml"));
                }
                getData = s => arc.HasFile(s) ? arc.GetBytes(s) : null;
            }

            if (doc != null)
            {
                m.Author      = doc.SelectSingleNode("/ModInfo/Author").NodeTextS();
                m.Link        = doc.SelectSingleNode("/ModInfo/Link").NodeTextS();
                m.Description = doc.SelectSingleNode("/ModInfo/Description").NodeTextS();
                decimal ver;
                if (decimal.TryParse(doc.SelectSingleNode("/ModInfo/Version").NodeTextS().Replace(',', '.'), out ver))
                {
                    m.LatestVersion.Version = ver;
                }
                var pv = doc.SelectSingleNode("/ModInfo/PreviewFile");
                if (pv != null)
                {
                    byte[] data = getData(pv.InnerText);
                    if (data != null)
                    {
                        string url = "iros://Preview/Auto/" + m.ID.ToString();
                        m.LatestVersion.PreviewImage = url;
                        Sys.ImageCache.InsertManual(url, data);
                    }
                }
            }

            Sys.Library.AddInstall(new InstalledItem()
            {
                CachedDetails = m,
                CachePreview  = String.Empty,
                ModID         = m.ID,
                UpdateType    = UpdateType.Ignore,
                Versions      = new List <InstalledVersion>()
                {
                    new InstalledVersion()
                    {
                        VersionDetails = m.LatestVersion, InstalledLocation = location
                    }
                },
            });
        }
Example #6
0
        /// <summary>
        /// Parses mod.xml from a folder or .iro and returns the <see cref="Mod"/>
        /// </summary>
        /// <param name="sourceFileOrFolder">absolute path to folder or .iro file </param>
        /// <param name="defaultModIfMissing"> default mod properties to use if the mod.xml file is not found </param>
        /// <returns></returns>
        public Mod ParseModXmlFromSource(string sourceFileOrFolder, Mod defaultModIfMissing = null)
        {
            if (defaultModIfMissing == null)
            {
                defaultModIfMissing = new Mod()
                {
                    Author        = String.Empty,
                    Description   = "Imported mod",
                    Category      = "Unknown",
                    ID            = ParseModGuidFromFileOrFolderName(sourceFileOrFolder),
                    Link          = String.Empty,
                    Tags          = new List <string>(),
                    Name          = "",
                    LatestVersion = new ModVersion()
                    {
                        CompatibleGameVersions = GameVersions.All,
                        Links        = new List <string>(),
                        PreviewImage = String.Empty,
                        ReleaseDate  = DateTime.Now,
                        ReleaseNotes = String.Empty,
                        Version      = 1.00m,
                    }
                };
            }


            Mod parsedMod = Mod.CopyMod(defaultModIfMissing);

            if (string.IsNullOrWhiteSpace(sourceFileOrFolder))
            {
                return(parsedMod);
            }

            if (!File.Exists(sourceFileOrFolder) && !Directory.Exists(sourceFileOrFolder))
            {
                return(parsedMod);
            }

            bool isIroFile = sourceFileOrFolder.EndsWith(".iro");

            System.Xml.XmlDocument doc          = null;
            Func <string, byte[]>  getImageData = null;

            _7thWrapperLib.IrosArc arc = null;

            string[] musicFiles = FF7FileLister.GetMusicFiles();
            string[] movieFiles = FF7FileLister.GetMovieFiles().Keys.ToArray();


            if (isIroFile)
            {
                RaiseProgressChanged("Getting mod.xml data from .iro", 10);

                arc = new _7thWrapperLib.IrosArc(sourceFileOrFolder, patchable: false, (i, fileCount) =>
                {
                    double newProgress = 10.0 + ((double)i / fileCount) * 30.0;
                    RaiseProgressChanged($"Scanning .iro archive files {i} / {fileCount}", newProgress);
                });

                if (arc.HasFile("mod.xml"))
                {
                    doc = new System.Xml.XmlDocument();
                    doc.Load(arc.GetData("mod.xml"));
                }

                RaiseProgressChanged($"Scanning .iro archive files for movie and music files", 45);
                foreach (string file in arc.AllFileNames())
                {
                    if (musicFiles.Any(f => f.Equals(Path.GetFileName(file), StringComparison.InvariantCultureIgnoreCase)))
                    {
                        parsedMod.ContainsMusic = true;
                    }

                    if (movieFiles.Any(f => f.Equals(Path.GetFileName(file), StringComparison.InvariantCultureIgnoreCase)))
                    {
                        parsedMod.ContainsMovies = true;
                    }

                    if (parsedMod.ContainsMovies && parsedMod.ContainsMusic)
                    {
                        break; // break out of loop to stop scanning since confirmed both music and movie files exist in mod
                    }
                }


                getImageData = s =>
                {
                    return(arc.HasFile(s) ? arc.GetBytes(s) : null);
                };
            }
            else
            {
                string pathToModXml = Path.Combine(sourceFileOrFolder, "mod.xml");

                RaiseProgressChanged("Getting mod.xml data from file", 10);
                if (File.Exists(pathToModXml))
                {
                    doc = new System.Xml.XmlDocument();
                    doc.Load(pathToModXml);
                }

                RaiseProgressChanged($"Scanning mod folder for movie and music files", 25);
                foreach (string file in FileUtils.GetAllFilesInDirectory(sourceFileOrFolder))
                {
                    if (musicFiles.Any(f => f.Equals(Path.GetFileName(file), StringComparison.InvariantCultureIgnoreCase)))
                    {
                        parsedMod.ContainsMusic = true;
                    }

                    if (movieFiles.Any(f => f.Equals(Path.GetFileName(file), StringComparison.InvariantCultureIgnoreCase)))
                    {
                        parsedMod.ContainsMovies = true;
                    }

                    if (parsedMod.ContainsMovies && parsedMod.ContainsMusic)
                    {
                        break; // break out of loop to stop scanning since confirmed both music and movie files exist in mod
                    }
                }

                getImageData = s =>
                {
                    string file = Path.Combine(sourceFileOrFolder, s);
                    if (File.Exists(file))
                    {
                        return(File.ReadAllBytes(file));
                    }
                    return(null);
                };
            }


            if (doc != null)
            {
                RaiseProgressChanged("Parsing information from mod.xml", 50);

                //If mod.xml contains an ID GUID, then use that instead of generating random one
                string modidstr = doc.SelectSingleNode("/ModInfo/ID").NodeTextS();
                if (!string.IsNullOrWhiteSpace(modidstr))
                {
                    try
                    {
                        parsedMod.ID = new Guid(modidstr);
                    }
                    catch (Exception e)
                    {
                        Sys.Message(new WMessage("Invalid GUID found for Mod ID ... Using guid from file/folder name (or new guid).", WMessageLogLevel.LogOnly, e));
                        parsedMod.ID = ParseModGuidFromFileOrFolderName(sourceFileOrFolder);
                    }
                }

                parsedMod.Name = doc.SelectSingleNode("/ModInfo/Name").NodeTextS();
                if (string.IsNullOrWhiteSpace(parsedMod.Name))
                {
                    parsedMod.Name = defaultModIfMissing.Name;
                }

                parsedMod.Author = doc.SelectSingleNode("/ModInfo/Author").NodeTextS();
                if (string.IsNullOrWhiteSpace(parsedMod.Author))
                {
                    parsedMod.Author = defaultModIfMissing.Author;
                }


                parsedMod.Link = doc.SelectSingleNode("/ModInfo/Link").NodeTextS();
                if (string.IsNullOrWhiteSpace(parsedMod.Link))
                {
                    parsedMod.Link = defaultModIfMissing.Link;
                }

                parsedMod.Description = doc.SelectSingleNode("/ModInfo/Description").NodeTextS();
                if (string.IsNullOrWhiteSpace(parsedMod.Description))
                {
                    parsedMod.Description = defaultModIfMissing.Description;
                }

                parsedMod.Category = doc.SelectSingleNode("/ModInfo/Category").NodeTextS();
                if (string.IsNullOrWhiteSpace(parsedMod.Category))
                {
                    parsedMod.Category = defaultModIfMissing.Category;
                }

                parsedMod.LatestVersion.ReleaseNotes = doc.SelectSingleNode("/ModInfo/ReleaseNotes").NodeTextS();
                if (string.IsNullOrWhiteSpace(parsedMod.LatestVersion.ReleaseNotes))
                {
                    parsedMod.LatestVersion.ReleaseNotes = defaultModIfMissing.LatestVersion.ReleaseNotes;
                }


                if (DateTime.TryParse(doc.SelectSingleNode("/ModInfo/ReleaseDate").NodeTextS(), out DateTime parsedDate))
                {
                    parsedMod.LatestVersion.ReleaseDate = parsedDate;
                }
                else
                {
                    parsedMod.LatestVersion.ReleaseDate = defaultModIfMissing.LatestVersion.ReleaseDate;
                }

                string versionText = doc.SelectSingleNode("/ModInfo/Version").NodeTextS().Replace(',', '.'); // in-case Xml has "1,7" format then replace with "1.7"
                if (decimal.TryParse(versionText, System.Globalization.NumberStyles.AllowDecimalPoint, new System.Globalization.CultureInfo(""), out decimal ver))
                {
                    parsedMod.LatestVersion.Version = ver;
                }
                else
                {
                    parsedMod.LatestVersion.Version = defaultModIfMissing.LatestVersion.Version;
                }

                var pv = doc.SelectSingleNode("/ModInfo/PreviewFile");
                if (pv != null)
                {
                    // add the preview file to image cache and set the url prefixed with iros://Preview/Auto since it came from auto-import
                    byte[] data = getImageData(pv.InnerText);
                    if (data != null)
                    {
                        string url = $"iros://Preview/Auto/{parsedMod.ID}_{pv.InnerText.Replace('\\', '_')}";
                        parsedMod.LatestVersion.PreviewImage = url;
                        Sys.ImageCache.InsertManual(url, data);
                    }
                }
            }

            if (arc != null)
            {
                arc.Dispose();
            }

            return(parsedMod);
        }