Beispiel #1
0
        public override void Unpack(string targetDir, string name, Stream stream, IProgressIndicator progressIndicator)
        {
            progressIndicator?.SetProgress($"[{UnpackerName}]Loading FL Program: {name}", 1, 3);
            SerializableFLProgram prog = runner.Parser.Process(new FLParserInput(name));

            string filePath = Path.Combine(
                targetDir,
                name.Replace("/", "\\").StartsWith("\\")
                                               ? name.Replace("/", "\\").Substring(1)
                                               : name.Replace("/", "\\")
                );

            Directory.CreateDirectory(Path.GetDirectoryName(filePath));
            filePath = filePath + "c";

            progressIndicator?.SetProgress(
                $"[{UnpackerName}]Writing FL Program Output: {Path.GetFileNameWithoutExtension(name)}",
                3,
                3
                );
            Stream s = File.OpenWrite(filePath);

            FLSerializer.SaveProgram(s, prog, runner.InstructionSet, new string[0]);
            s.Dispose();
            progressIndicator?.Dispose();
        }
Beispiel #2
0
        public override void Unpack(string targetDir, string name, Stream stream, IProgressIndicator progressIndicator)
        {
            progressIndicator?.SetProgress($"[{UnpackerName}]Loading FL Program: {name}", 1, 3);
            SerializableFLProgram prog = FLSerializer.LoadProgram(stream, runner.InstructionSet);

            progressIndicator?.SetProgress($"[{UnpackerName}]Running FL Program: {name}", 2, 3);
            FLProgram p = runner.Run(prog, 512, 512, 1);

            string filePath = Path.Combine(
                targetDir,
                name.Replace("/", "\\").StartsWith("\\")
                                               ? name.Replace("/", "\\").Substring(1)
                                               : name.Replace("/", "\\")
                );

            Directory.CreateDirectory(Path.GetDirectoryName(filePath));
            filePath = filePath.Remove(filePath.Length - 3, 3) + "png";

            progressIndicator?.SetProgress(
                $"[{UnpackerName}]Writing FL Program Output: {Path.GetFileNameWithoutExtension(name)}",
                3,
                3
                );
            Bitmap bmp = new Bitmap(512, 512);

            CLAPI.UpdateBitmap(runner.Instance, bmp, p.GetActiveBuffer(false).Buffer);
            bmp.Save(filePath);
            stream.Close();
            p.FreeResources();
            progressIndicator?.Dispose();
        }
        private void CopyDirectory(string source, string target, IProgressIndicator indicator)
        {
            Directory.CreateDirectory(target);
            if (!Directory.Exists(source))
            {
                return;
            }

            string[] files = Directory.GetFiles(source, "*", SearchOption.AllDirectories);
            for (int i = 0; i < files.Length; i++)
            {
                string file = files[i];
                indicator.SetProgress("Copying File:" + file, i, files.Length - 1);
                string dstFile = file.Replace(source, target);
                try
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(dstFile));
                    File.Copy(file, dstFile);
                }
                catch (Exception e)
                {
                }
            }

            indicator.Dispose();
        }
Beispiel #4
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();
        }
Beispiel #5
0
        public override void Unpack(string targetDir, string name, Stream stream, IProgressIndicator progressIndicator)
        {
            progressIndicator?.SetProgress($"[{UnpackerName}]Loading FL Program: {name}", 1, 3);
            FLProgram p = null;

            try
            {
                SerializableFLProgram prog = runner.Parser.Process(
                    new FLParserInput(
                        name,
                        new StreamReader(stream)
                        .ReadToEnd().Split('\n')
                        .Select(x => x.Trim()).ToArray(),
                        true
                        )
                    );

                progressIndicator?.SetProgress($"[{UnpackerName}]Running FL Program: {name}", 2, 3);


                p = runner.Build(prog);
                if (p.HasMain)
                {
                    runner.Run(p, 512, 512, 1);

                    string filePath = Path.Combine(
                        targetDir,
                        name.Replace("/", "\\").StartsWith("\\")
                                                       ? name.Replace("/", "\\").Substring(1)
                                                       : name.Replace("/", "\\")
                        );
                    Directory.CreateDirectory(Path.GetDirectoryName(filePath));
                    filePath = filePath.Remove(filePath.Length - 2, 2) + "png";

                    progressIndicator?.SetProgress(
                        $"[{UnpackerName}]Writing FL Program Output: {Path.GetFileNameWithoutExtension(name)}",
                        3,
                        3
                        );
                    Bitmap bmp = new Bitmap(512, 512);
                    CLAPI.UpdateBitmap(runner.Instance, bmp, p.GetActiveBuffer(false).Buffer);
                    bmp.Save(filePath);
                }
            }
            catch (Exception)
            {
            }

            stream.Close();
            p?.FreeResources();
            progressIndicator?.Dispose();
        }
Beispiel #6
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();
        }
Beispiel #7
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(Path.GetDirectoryName(filePath));
            Stream s = File.OpenWrite(filePath);

            progressIndicator?.SetProgress($"[{UnpackerName}]Unpacking: {name}", 2, 2);
            stream.CopyTo(s);
            s.Close();
            stream.Close();
            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();
            }
        }
Beispiel #9
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();
            }
        }