Ejemplo n.º 1
0
        public ModFile(ModManager modManager, string wadLocation, string rawLocation, ModInfo info, Image image)
        {
            this._modManager = modManager;
            using (FileStream fileStream = new FileStream(string.Format(@"{0}\{1}.zip", ModManager.MOD_FOLDER, info.CreateID()), FileMode.Create))
            {
                using (this.Content = new ZipArchive(fileStream, ZipArchiveMode.Update))
                {
                    this._info  = info;
                    this._image = image;

                    if (!string.IsNullOrEmpty(wadLocation))
                    {
                        //Check if we want to pack the WAD folders into WAD files
                        if (Config.Get <bool>("PackWadFolders"))
                        {
                            PackWadFolders(wadLocation);

                            foreach (string wadFile in Directory.EnumerateFiles(wadLocation))
                            {
                                AddFile(string.Format("WAD\\{0}", Path.GetFileName(wadFile)), File.ReadAllBytes(wadFile));
                            }
                        }
                        else
                        {
                            AddFolder("WAD", wadLocation);
                        }
                    }

                    if (!string.IsNullOrEmpty(rawLocation))
                    {
                        AddFolder("RAW", rawLocation);
                    }

                    AddFile(@"META\info.json", Encoding.ASCII.GetBytes(info.Serialize()));

                    if (image != null)
                    {
                        using (MemoryStream imageStream = new MemoryStream())
                        {
                            image.Save(imageStream, ImageFormat.Png);
                            AddFile(@"META\image.png", imageStream.ToArray());
                        }
                    }
                }
            }

            this.Content = ZipFile.OpenRead(string.Format(@"{0}\{1}.zip", ModManager.MOD_FOLDER, this.GetID()));
        }
Ejemplo n.º 2
0
        public ModFile(LeagueFileIndex index, IEnumerable <string> wadFilePaths, IEnumerable <string> wadFolderPaths, ModInfo info, Image image)
        {
            this._file = string.Format(@"{0}\{1}.fantome", ModManager.MOD_FOLDER, info.CreateID());

            using (FileStream fileStream = new FileStream(this._file, FileMode.Create))
            {
                using (this.Content = new ZipArchive(fileStream, ZipArchiveMode.Update))
                {
                    this._info  = info;
                    this._image = image;

                    foreach (string wadFolderPath in wadFolderPaths)
                    {
                        //Check if we want to pack the WAD folder into a WAD file
                        if (Config.Get <bool>("PackWadFolders"))
                        {
                            PackWadFolder(wadFolderPath);
                        }
                        else
                        {
                            AddFolder("WAD", wadFolderPath);
                        }
                    }

                    foreach (string wadFilePath in wadFilePaths)
                    {
                        string wadFileName = Path.GetFileName(wadFilePath);
                        string wadPath     = index.FindWADPath(wadFileName);

                        AddFile($"WAD/{wadFileName}", File.ReadAllBytes(wadFilePath));
                    }

                    AddFile("META/info.json", Encoding.ASCII.GetBytes(info.Serialize()));

                    if (image != null)
                    {
                        using (MemoryStream imageStream = new MemoryStream())
                        {
                            image.Save(imageStream, ImageFormat.Png);
                            AddFile("META/image.png", imageStream.ToArray());
                        }
                    }
                }
            }

            this.Content = ZipFile.OpenRead(string.Format(@"{0}\{1}.fantome", ModManager.MOD_FOLDER, this.GetID()));
        }