Beispiel #1
0
        public void ShowDialog(IWin32Window owner)
        {
            string WinAPEFullPath   = Host.GetPluginsPath() + "WinAPE.exe";
            string arguments        = String.Empty;
            string initialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

            Host.StartProcess(WinAPEFullPath, arguments, initialDirectory, false);
        }
Beispiel #2
0
        public bool CompileASM(PhactoryHost.Database.Resource resource)
        {
            if (resource.IdOutputs.Count == 1)
            {
                PhactoryHost.Database.Resource outputResource = Host.GetResource(resource.IdOutputs[0]);

                if (Host.IsResourceReferencedByOtherResources(outputResource).Count == 0)
                {
                    // simply skip compilation
                    return(true);
                }
            }

            FileInfo fileInfo = Host.GetFileInfo(resource);

            if (fileInfo == null)
            {
                return(false);
            }

            string exeFullPath = Host.GetPluginsPath() + "Pasmo.exe";
            string arguments   = "--bin \"" + fileInfo.FullName + "\" \"" + fileInfo.FullName.Replace(".asm", ".bin") + "\"";

            bool isOK = Host.StartProcess(exeFullPath, arguments, fileInfo.DirectoryName, true);

            if (isOK)
            {
                if (Host.GetLastErrorOutput().ToUpper().IndexOf("ERROR") != -1)
                {
                    isOK = false;
                    Host.Log("\nCompilation failed with '" + resource.DisplayName + "'..\nLog output:\n" + Host.GetLastErrorOutput());
                }
            }

            return(isOK);
        }
Beispiel #3
0
        private bool ConvertDSK(string filename)
        {
            var dskFileInfo = new FileInfo(filename);

            string tempDir = "\\HFE_CONVERT";

            Directory.CreateDirectory(tempDir);

            string src = tempDir + "\\" + dskFileInfo.Name;

            if (File.Exists(src))
            {
                File.Delete(src);
            }
            File.Copy(dskFileInfo.FullName, src);

            string hfeConverterFullPath = _host.GetPluginsPath() + "flopimage_convert.exe";

            string arguments = tempDir + " " + tempDir + " -HFE";

            if (_host.IsVerboseOutput())
            {
                _host.Log(hfeConverterFullPath + " " + arguments);
            }

            string dst = "";

            bool isOK = _host.StartProcess(hfeConverterFullPath, arguments, tempDir, true);

            if (isOK)
            {
                string dskhfe = src.Replace(".dsk", "_dsk.hfe");
                dst = dskFileInfo.FullName.Replace(".dsk", ".hfe");

                if (File.Exists(dst))
                {
                    File.Delete(dst);
                }
                File.Copy(dskhfe, dst);

                File.Delete(src);
                File.Delete(dskhfe);
            }

            Directory.Delete(tempDir);

            return(File.Exists(dst));
        }
Beispiel #4
0
        public bool Compile(PhactoryHost.Database.Resource resource)
        {
            FileInfo fileInfo = Host.GetFileInfo(resource);

            if (fileInfo == null)
            {
                return(false);
            }

            if (!IsResourceSupported(resource))
            {
                return(false);
            }

            bool isOK = true;

            string DSKFilename = Host.GetFileInfo(resource).FullName;

            DSKFilename = DSKFilename.Replace(".cpcdsk", ".dsk");
            FileInfo DSKFileInfo = new FileInfo(DSKFilename);

            Host.Log(new FileInfo(DSKFilename).Name);

            Document.Document document = Host.XMLRead <Document.Document>(Host.GetFileInfo(resource).FullName);
            if (!(document is Document.Document))
            {
                return(false);
            }

            // create empty DSK
            if (document.TrackLoaderDisc)
            {
                App.Controller.View.AppDoEvents();

                if (File.Exists(DSKFilename))
                {
                    try
                    {
                        File.Delete(DSKFilename);
                    }
                    catch
                    {
                        Host.Log("Can't delete " + DSKFilename + " - is the file locked by other process ?");
                    }
                }
                try
                {
                    string discsysExeFullPath = Host.GetPluginsPath() + "discsys.exe";
                    var    arguments          = "-f \"myd\" " + DSKFileInfo.FullName;

                    if (Host.IsVerboseOutput())
                    {
                        Host.Log(discsysExeFullPath + " " + arguments);
                    }

                    isOK = Host.StartProcess(discsysExeFullPath, arguments, fileInfo.DirectoryName, true);
                }
                catch
                {
                }
            }
            else
            {
                string dskTemplateFilename = Host.GetPluginsPath() + "Empty.dsk";
                if (File.Exists(DSKFilename))
                {
                    try
                    {
                        File.Delete(DSKFilename);
                    }
                    catch
                    {
                        Host.Log("Can't delete " + DSKFilename + " - is the file locked by other process ?");
                    }
                }
                try
                {
                    File.Copy(dskTemplateFilename, DSKFilename);
                }
                catch
                {
                }
            }

            // copy files into DSK
            if (document.TrackLoaderDisc)
            {
                foreach (Document.Item item in document.Items)
                {
                    PhactoryHost.Database.Resource depResource = Host.GetResource(item.ResourceID);
                    if (depResource == null)
                    {
                        Host.Log("Unknown resource identifier : " + item.ResourceID);
                        return(false);
                    }

                    FileInfo depFileInfo = Host.GetFileInfo(depResource);

                    if (!item.TrackLoaderItem)
                    {
                        // addhead -a -t "binary" -s 8192 -x 8192 boot.bin boot.bin

                        string addheadExeFullPath = Host.GetPluginsPath() + "addhead.exe";

                        string arguments = String.Empty;

                        if (item.ItemType == Document.ItemType.Basic)
                        {
                            arguments  = "-a -t \"basic\" ";
                            arguments += "-s " + 368 + " ";
                            arguments += "-x " + 368 + " ";
                            arguments += depFileInfo.FullName + " ";

                            arguments += "\"" + Path.GetTempPath() + item.AmsdosFilename + "\"";
                        }
                        else
                        {
                            arguments  = "-a -t \"binary\" ";
                            arguments += "-s " + item.LoadAdress + " ";
                            arguments += "-x " + item.ExecAdress + " ";
                            arguments += depFileInfo.FullName + " ";
                            arguments += "\"" + Path.GetTempPath() + item.AmsdosFilename + "\"";
                        }


                        if (Host.IsVerboseOutput())
                        {
                            Host.Log(addheadExeFullPath + " " + arguments);
                        }

                        isOK = Host.StartProcess(addheadExeFullPath, arguments, fileInfo.DirectoryName, true);
                        if (isOK)
                        {
                            string cpcxfsExeFullPath = Host.GetPluginsPath() + "cpcxfs.exe";
                            var    dstCpcXfsExe      = Path.GetTempPath() + new FileInfo(cpcxfsExeFullPath).Name;
                            var    dstCpmDisksDef    = Path.GetTempPath() + "cpmdisks.def";
                            if (!File.Exists(dstCpcXfsExe))
                            {
                                File.Copy(cpcxfsExeFullPath, dstCpcXfsExe, true);
                            }
                            if (!File.Exists(dstCpmDisksDef))
                            {
                                File.Copy(Host.GetPluginsPath() + "cpmdisks.def", dstCpmDisksDef, true);
                            }

                            arguments  = "-o MLOD " + DSKFilename + " -f -b -p ";
                            arguments += "\"" + Path.GetTempPath() + item.AmsdosFilename + "\"";
                            if (Host.IsVerboseOutput())
                            {
                                Host.Log(cpcxfsExeFullPath + " " + arguments);
                            }

                            isOK = Host.StartProcess(cpcxfsExeFullPath, arguments, Path.GetTempPath(), true);

                            var lastErrorOutput    = Host.GetLastErrorOutput();
                            var lastStandardOutput = Host.GetLastStandardOutput();

                            App.Controller.View.AppDoEvents();

                            if (File.Exists(dstCpcXfsExe))
                            {
                                File.Delete(dstCpcXfsExe);
                            }
                            if (File.Exists(dstCpmDisksDef))
                            {
                                File.Delete(dstCpmDisksDef);
                            }
                        }

                        if (File.Exists(Path.GetTempPath() + item.AmsdosFilename))
                        {
                            File.Delete(Path.GetTempPath() + item.AmsdosFilename);
                        }
                    }
                }

                int itemCount = 0;
                var content   = String.Empty;
                foreach (Document.Item item in document.Items)
                {
                    PhactoryHost.Database.Resource depResource = Host.GetResource(item.ResourceID);
                    if (depResource == null)
                    {
                        Host.Log("Unknown resource identifier : " + item.ResourceID);
                        return(false);
                    }

                    if (item.TrackLoaderItem)
                    {
                        // discsys test.dsk 1 sabotr2.ayc

                        FileInfo depFileInfo = Host.GetFileInfo(depResource);

                        content += itemCount + " \"" + depFileInfo.FullName + "\"\n";

                        itemCount++;
                    }
                }

                string fileListFilename = Host.GetFileInfo(resource).FullName;
                fileListFilename = fileListFilename.Replace(".cpcdsk", ".filelist");
                File.WriteAllText(fileListFilename, content);

                // discsys test.dsk 1 sabotr2.ayc

                var discsysExeFullPath = Host.GetPluginsPath() + "discsys.exe";
                var disksysArguments   = "-l \"" + fileListFilename + "\" \"" + DSKFilename + "\"";

                if (Host.IsVerboseOutput())
                {
                    Host.Log(discsysExeFullPath + " " + disksysArguments);
                }
                isOK = Host.StartProcess(discsysExeFullPath, disksysArguments, fileInfo.DirectoryName, true);
            }
            else
            {
                string exeFullPath = Host.GetPluginsPath() + "ManageDSK.EXE";

                foreach (Document.Item item in document.Items)
                {
                    App.Controller.View.AppDoEvents();

                    PhactoryHost.Database.Resource depResource = Host.GetResource(item.ResourceID);
                    if (depResource == null)
                    {
                        Host.Log("Unknown resource identifier : " + item.ResourceID);
                        return(false);
                    }

                    FileInfo depFileInfo = Host.GetFileInfo(depResource);

                    string arguments = "-L\"" + DSKFileInfo.FullName + "\" ";

                    arguments += "-I\"" + depFileInfo.FullName + "\"";

                    arguments += "/" + item.AmsdosFilename;

                    if (item.ItemType == Document.ItemType.Basic)
                    {
                        arguments += "/BAS/368";
                    }
                    else
                    {
                        arguments += "/BIN";

                        arguments += "/" + item.LoadAdress;
                        arguments += "/" + item.ExecAdress;
                    }

                    arguments += " ";

                    arguments += "-S\"" + DSKFileInfo.FullName + "\"";

                    if (Host.IsVerboseOutput())
                    {
                        Host.Log(exeFullPath + " " + arguments);
                    }

                    isOK = Host.StartProcess(exeFullPath, arguments, fileInfo.DirectoryName, true);
                    if (isOK)
                    {
                        if (Host.GetLastErrorOutput().ToUpper().IndexOf("ERREUR") != -1)
                        {
                            isOK = false;
                        }
                    }

                    if (item.CopyToWinAPEROMFolder)
                    {
                        string romFilename     = item.AmsdosFilename; // depFileInfo.Name.Replace(depFileInfo.Extension, ".ROM");
                        string destROMFilename = Host.GetPluginsPath() + "ROM\\" + romFilename;
                        if (File.Exists(destROMFilename))
                        {
                            File.Delete(destROMFilename);
                        }
                        File.Copy(depFileInfo.FullName, destROMFilename);

                        App.Controller.View.AppDoEvents();
                    }
                }
            }

            if (document.GenerateHFE)
            {
                Host.Log(new FileInfo(DSKFilename.Replace(".dsk", ".hfe")).Name);

                string tempDir = "\\HFE_CONVERT";

                App.Controller.View.AppDoEvents();

                Directory.CreateDirectory(tempDir);

                App.Controller.View.AppDoEvents();

                string src = tempDir + "\\" + DSKFileInfo.Name;
                if (File.Exists(src))
                {
                    File.Delete(src);
                }
                File.Copy(DSKFileInfo.FullName, src);

                App.Controller.View.AppDoEvents();

                string hfeConverterFullPath = Host.GetPluginsPath() + "flopimage_convert.exe";

                string arguments = tempDir + " " + tempDir + " -HFE";

                if (Host.IsVerboseOutput())
                {
                    Host.Log(hfeConverterFullPath + " " + arguments);
                }

                string dst = "";

                isOK = Host.StartProcess(hfeConverterFullPath, arguments, fileInfo.DirectoryName, true);
                if (isOK)
                {
                    string dskhfe = src.Replace(".dsk", "_dsk.hfe");
                    dst = DSKFileInfo.FullName.Replace(".dsk", ".hfe");

                    App.Controller.View.AppDoEvents();

                    if (File.Exists(dst))
                    {
                        File.Delete(dst);
                    }
                    if (File.Exists(dskhfe))
                    {
                        File.Copy(dskhfe, dst);
                        File.Delete(dskhfe);
                    }

                    File.Delete(src);
                }

                App.Controller.View.AppDoEvents();

                Directory.Delete(tempDir, true);

                if (File.Exists(dst) == false)
                {
                    isOK = false;
                }
            }

            return(isOK);
        }
Beispiel #5
0
        public bool Compile(PhactoryHost.Database.Resource resource)
        {
            FileInfo fileInfo = Host.GetFileInfo(resource);

            if (fileInfo == null)
            {
                return(false);
            }

            if (!IsResourceSupported(resource))
            {
                return(false);
            }

            bool isOK = true;

            int totalOriginalSize = 0;
            int totalPackedSize   = 0;

            Document.Document document = Host.XMLRead <Document.Document>(Host.GetFileInfo(resource).FullName);
            if (document is Document.Document)
            {
                switch (document.PackerType)
                {
                default:
                case CPCPacker.Document.PackerType.Exomizer:
                    Host.Log("Using Exomizer...");
                    break;

                case CPCPacker.Document.PackerType.BitBuster:
                    Host.Log("Using BitBuster...");
                    break;
                }

                var allTasks = new List <Task>();

                foreach (Document.Item item in document.Items)
                {
                    App.Controller.View.AppDoEvents();

                    PhactoryHost.Database.Resource depResource = Host.GetResource(item.ResourceID);
                    if (depResource == null)
                    {
                        Host.Log("Unknown resource identifier : " + item.ResourceID);
                        return(false);
                    }

                    var task = new Task(() =>
                    {
                        FileInfo depFileInfo = Host.GetFileInfo(depResource);

                        //Host.Log("  +" + depResource.DisplayName + "...");

                        int originalSize        = (int)depFileInfo.Length;
                        bool switchedToExomizer = false;
                        bool switchedToRaw      = false;

                        string exeFullPath = Host.GetPluginsPath();
                        string arguments   = "";

                        var packerType = document.PackerType;

                        switch (packerType)
                        {
                        default:
                        case CPCPacker.Document.PackerType.Exomizer:
                            exeFullPath += "exomizer.exe";
                            arguments    = "raw \"" + depFileInfo.Name + "\" -o \"" + depFileInfo.Name + ".temp.pck\"";

                            isOK = Host.StartProcess(exeFullPath, arguments, fileInfo.DirectoryName, true);
                            break;

                        case CPCPacker.Document.PackerType.BitBuster:
                            exeFullPath += "BitBuster.exe";
                            arguments    = "\"" + depFileInfo.Name + "\"";

                            if (File.Exists(depFileInfo.FullName + ".pck"))
                            {
                                File.Delete(depFileInfo.FullName + ".pck");
                            }

                            isOK = Host.StartProcess(exeFullPath, arguments, fileInfo.DirectoryName, true);

                            isOK = File.Exists(depFileInfo.FullName + ".pck");

                            if (isOK)
                            {
                                // UNCOMMENT THIS BLOCK IF YOU WANT EXOMIZER FALLBACK IN CASE OF PACK FAIL WITH BITBUSTER

                                /*
                                 * int packedSize = (int)new FileInfo(depFileInfo.FullName + ".pck").Length;
                                 * if (originalSize<packedSize)
                                 * {
                                 *  switchedToExomizer = true;
                                 *  isOK = false;
                                 * }*/
                            }

                            if (!isOK)
                            {
                                isOK = true;
                                switchedToExomizer = true;
                                packerType         = Document.PackerType.Exomizer;

                                exeFullPath = Host.GetPluginsPath() + "exomizer.exe";
                                arguments   = "raw \"" + depFileInfo.Name + "\" -o \"" + depFileInfo.Name + ".temp.pck\"";

                                isOK = Host.StartProcess(exeFullPath, arguments, fileInfo.DirectoryName, true);
                            }
                            break;
                        }

                        if (isOK)
                        {
                            int packedSize      = 0;
                            string destFullName = depFileInfo.FullName + ".pck";

                            switch (packerType)
                            {
                            default:
                            case CPCPacker.Document.PackerType.Exomizer:
                                exeFullPath = Host.GetPluginsPath() + "exoopt.exe";
                                arguments   = depFileInfo.Name + ".temp.pck " + depFileInfo.Name + ".pck";

                                isOK = Host.StartProcess(exeFullPath, arguments, fileInfo.DirectoryName, true);

                                File.Delete(depFileInfo.FullName + ".temp.pck");

                                if (isOK)
                                {
                                    FileInfo outFileInfo = new FileInfo(destFullName);

                                    if (outFileInfo.Exists)
                                    {
                                        packedSize = (int)outFileInfo.Length;

                                        InsertPackerType(destFullName, 0, 0);
                                    }
                                }
                                break;

                            case CPCPacker.Document.PackerType.BitBuster:
                                {
                                    string result = Host.GetLastErrorOutput();

                                    packedSize = (int)new FileInfo(destFullName).Length;

                                    if (packedSize < originalSize)
                                    {
                                        InsertPackerType(destFullName, 1, 0);
                                    }
                                    else
                                    {
                                        switchedToRaw = true;
                                        try
                                        {
                                            File.Copy(depFileInfo.FullName, destFullName, true);
                                        }
                                        catch
                                        {
                                            Host.Log(depFileInfo.FullName + " : failed to copy source file !");
                                        }

                                        InsertPackerType(destFullName, 2, (uint)originalSize);
                                    }
                                }
                                break;
                            }

                            if (isOK)
                            {
                                string logLine = depResource.DisplayName + ".pck (" + originalSize + " => " + packedSize;
                                if (packedSize >= originalSize)
                                {
                                    logLine += " bytes, pack failed)";
                                    // isOK = false;
                                    isOK = true;
                                }
                                else
                                {
                                    logLine += " bytes)";
                                }
                                if (switchedToExomizer)
                                {
                                    logLine += " (switched to Exomizer)";
                                }
                                else if (switchedToRaw)
                                {
                                    logLine += " (switched to raw)";
                                }

                                Host.Log("  +" + logLine);

                                totalOriginalSize += originalSize;
                                totalPackedSize   += packedSize;
                            }
                        }
                    });

                    allTasks.Add(task);
                }

                foreach (var task in allTasks)
                {
                    task.Start();

                    Thread.Sleep(20);
                    Application.DoEvents();
                }

                int aliveCount = 0;
                do
                {
                    aliveCount = allTasks.Count;

                    foreach (var task in allTasks)
                    {
                        if (task.IsCompleted)
                        {
                            aliveCount--;
                        }
                        else if (task.IsFaulted)
                        {
                            aliveCount--;
                        }
                    }

                    Thread.Sleep(100);
                    Application.DoEvents();
                } while (aliveCount != 0);
            }

            if (isOK)
            {
                //Host.Log("  = " + totalOriginalSize + " => " + totalPackedSize + " bytes");
            }

            return(isOK);
        }