Exemplo n.º 1
0
        private void UnpackPackage(IProgressIndicator indicator, string filename, bool createSubfolder = false)
        {
            indicator.SetProgress("Loading Package: " + filename, 1, 2);

            string name = ResourceManager.Load(filename);

            if (name == null)
            {
                return;
            }

            string path = Directory.GetCurrentDirectory();

            if (createSubfolder)
            {
                Directory.CreateDirectory(name);
                path = Path.Combine(path, name);
            }

            IProgressIndicator sub = indicator.CreateSubTask();

            ResourceManager.Activate(name, sub, path);
            indicator.SetProgress("Activating Package: " + name, 2, 2);
            indicator.Dispose();
        }
Exemplo n.º 2
0
        public static void Create(
            string folder, string targetFile, string name, string unpackerConfig, IProgressIndicator ProgressInfo)
        {
            ResourcePackInfo info = new ResourcePackInfo
            {
                Name           = name,
                UnpackerConfig = unpackerConfig
            };

            ProgressInfo?.SetProgress("Writing Package Info: " + info, 1, 2);
            XmlSerializer xs = new XmlSerializer(typeof(ResourcePackInfo));
            Stream        s  = File.OpenWrite(Path.Combine(folder, "Info.xml"));

            xs.Serialize(s, info);
            s.Dispose();

            ProgressInfo?.SetProgress("Creating Package from Folder: " + folder, 1, 2);

            ZipArchive arch = new ZipArchive(File.OpenWrite(targetFile), ZipArchiveMode.Create);

            string[] files = Directory.GetFiles(folder, "*", SearchOption.AllDirectories);

            IProgressIndicator perFileProgressIndicator = ProgressInfo?.CreateSubTask();

            for (int i = 0; i < files.Length; i++)
            {
                perFileProgressIndicator?.SetProgress("Packing File: " + files[i], i, files.Length - 1);
                try
                {
                    string zipLocation = files[i].Replace(
                        folder.EndsWith("\\") || folder.EndsWith("/")
                                                              ? folder
                                                              : folder + "\\",
                        ""
                        );
                    ZipArchiveEntry entry   = arch.CreateEntry(zipLocation);
                    Stream          filestr = File.OpenRead(files[i]);
                    Stream          zipstr  = entry.Open();
                    filestr.CopyTo(zipstr);
                    filestr.Close();
                    zipstr.Close();
                }
                catch (Exception)
                {
                }
            }

            arch.Dispose();

            File.Delete(Path.Combine(folder, "Info.xml"));
        }
Exemplo n.º 3
0
        public override void Unpack(string targetDir, string name, Stream stream, IProgressIndicator progressIndicator)
        {
            progressIndicator?.SetProgress($"[{UnpackerName}]Preparing Target Directory...", 1, 2);
            string filePath = Path.Combine(
                targetDir,
                name.Replace("/", "\\").StartsWith("\\")
                                               ? name.Replace("/", "\\").Substring(1)
                                               : name.Replace("/", "\\")
                );

            Directory.CreateDirectory(filePath);
            progressIndicator?.SetProgress($"[{UnpackerName}]Unpacking: {name}", 2, 2);

            string packname = ResourceManager.Load(name);

            ResourceManager.Activate(packname, progressIndicator?.CreateSubTask(), filePath);
            progressIndicator?.Dispose();
        }
        private void btnCreatePackage_Click(object sender, EventArgs e)
        {
            if (sfdSavePackage.ShowDialog() == DialogResult.OK)
            {
                string curDir = Directory.GetCurrentDirectory();

                IProgressIndicator ind = ProgressIndicator.CreateProgressIndicator(panelProgress);
                ind.SetProgress("Running Preparations.", 0, 2);
                if (cbExport.Checked)
                {
                    IProgressIndicator preps = ind.CreateSubTask(false);
                    preps.SetProgress("Copying Folder Contents...", 0, 1);

                    string dir = Path.Combine(
                        Path.GetDirectoryName(Directory.GetCurrentDirectory()),
                        "temp_" +
                        Path.GetFileNameWithoutExtension(Directory.GetCurrentDirectory())
                        );
                    CopyDirectory(Directory.GetCurrentDirectory(), dir, preps.CreateSubTask(false));
                    Directory.SetCurrentDirectory(dir);
                    string[] files = Directory.GetFiles(dir, "*.fl", SearchOption.AllDirectories);
                    preps.SetProgress("Exporting FL Scripts..", 0, 1);
                    IProgressIndicator fl2flc  = ind.CreateSubTask(false);
                    IProgressIndicator fl2flcf = fl2flc.CreateSubTask(false);
                    for (int i = 0; i < files.Length; i++)
                    {
                        string file = files[i];

                        fl2flc.SetProgress("Exporting File:" + file, i, files.Length);
                        fl2flcf.SetProgress("Parsing..", 0, 1);
                        Editor.Path = file;
                        Editor.FLContainer.SerializedProgram = null;

                        //Editor.InitProgram();
                        Editor.Build();
                        if (Editor.FLContainer.SerializedProgram == null)
                        {
                            return;
                        }

                        fl2flcf.SetProgress("Exporting..", 1, 1);
                        string f      = file + "c";
                        Stream stream = File.OpenWrite(f);
                        FLSerializer.SaveProgram(
                            stream,
                            Editor.FLContainer.SerializedProgram,
                            Editor.FLContainer.InstructionSet,
                            new string[0]
                            );
                        stream.Close();
                        if (!cbKeepFlScripts.Checked)
                        {
                            File.Delete(file);
                        }
                    }

                    fl2flcf.Dispose();
                    fl2flc.Dispose();
                    preps.Dispose();
                }

                ind.SetProgress("Creating Package.", 1, 2);
                ProgressIndicator.RunTask(
                    indicator => ResourceManager.Create(
                        Directory.GetCurrentDirectory(),
                        sfdSavePackage.FileName,
                        tbPackageName.Text,
                        tbUnpackConfig.Text,
                        indicator
                        ),
                    panelProgress,
                    Application.DoEvents,
                    ind.CreateSubTask(false)
                    );

                ind.SetProgress("Cleaning Up.", 2, 2);
                string oldDir = Directory.GetCurrentDirectory();
                Directory.SetCurrentDirectory(curDir);
                if (cbExport.Checked)
                {
                    Directory.Delete(oldDir, true);
                }

                Close();
                ind.Dispose();
            }
        }
Exemplo n.º 5
0
        public static void Activate(string name, IProgressIndicator ProgressInfo, string targetDir = null)
        {
            if (targetDir == null)
            {
                targetDir = ResourceDirectory;
            }

            if (LoadedPacks.ContainsKey(name))
            {
                ProgressInfo?.SetProgress("Loading Package...", 1, 3);
                Stream     archStream = IOManager.GetStream(LoadedPacks[name].ResourceData);
                ZipArchive arch       = new ZipArchive(archStream);

                ProgressInfo?.SetProgress("Preparing Unpackers...", 2, 3);
                Dictionary <string, string[]> unpackers = new Dictionary <string, string[]>(
                    LoadedPacks[name]
                    .UnpackerConfig
                    .Split(
                        new[] { ';' },
                        StringSplitOptions
                        .RemoveEmptyEntries
                        ).Select(
                        x =>
                {
                    KeyValuePair
                    <string
                     , string
                     []
                    >
                    ret
                        =
                            new
                            KeyValuePair
                            <string
                             , string
                             []
                            >(
                                x.Split(
                                    '+'
                                    )[0],
                                x.Split(
                                    '+'
                                    )
                                );
                    List <
                        string
                        > temp
                        = ret
                          .Value
                          .Select(y => y == "" ? y : "." + y)
                          .ToList();
                    temp
                    .RemoveAt(
                        0
                        );
                    ret =
                        new
                        KeyValuePair
                        <string
                         , string
                         []
                        >(
                            ret
                            .Key,
                            temp
                            .ToArray()
                            );
                    return
                    (ret);
                }
                        ).ToDictionary(
                        x =>
                        x.Key,
                        y =>
                        y.Value
                        )
                    );

                ProgressInfo?.SetProgress("Unpacking...", 3, 3);
                IProgressIndicator perFileProgress = ProgressInfo?.CreateSubTask();
                int fileCount = 0;
                for (int i = 0; i < arch.Entries.Count; i++)
                {
                    if (arch.Entries[i].Name == "Info.xml")
                    {
                        continue;
                    }

                    bool unpacked = false;
                    foreach (KeyValuePair <string, string[]> keyValuePair in unpackers)
                    {
                        if (keyValuePair.Value.Contains(Path.GetExtension(arch.Entries[i].Name)))
                        {
                            ResourceTypeUnpacker u =
                                Unpacker.FirstOrDefault(x => x.UnpackerName == keyValuePair.Key);
                            if (u == null)
                            {
                                continue;
                            }

                            perFileProgress?.SetProgress(
                                "Unpacking:" + arch.Entries[i].FullName,
                                fileCount,
                                arch.Entries.Count - 1
                                );
                            fileCount++;
                            u.Unpack(
                                targetDir,
                                arch.Entries[i].FullName,
                                arch.Entries[i].Open(),
                                perFileProgress?.CreateSubTask()
                                );
                            unpacked = true;
                            break;
                        }
                    }

                    if (!unpacked)
                    {
                        perFileProgress?.SetProgress(
                            "Unpacking:" + arch.Entries[i].FullName,
                            fileCount,
                            arch.Entries.Count - 1
                            );
                        fileCount++;
                        string key = unpackers.Where(x => x.Value.Length == 0).Select(x => x.Key).FirstOrDefault();
                        if (key == null)
                        {
                            continue;
                        }

                        ResourceTypeUnpacker u =
                            Unpacker.FirstOrDefault(x => x.UnpackerName == key);
                        if (u == null)
                        {
                            continue;
                        }

                        u.Unpack(
                            targetDir,
                            arch.Entries[i].FullName,
                            arch.Entries[i].Open(),
                            perFileProgress?.CreateSubTask()
                            );
                    }
                }

                perFileProgress?.Dispose();
                ProgressInfo?.Dispose();
            }
        }