示例#1
0
        public bool Compile(PhactoryHost.Database.Resource resource)
        {
            FileInfo fileInfo = Host.GetFileInfo(resource);

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

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

            List <String> resourceFilenames = new List <String>();
            List <String> paddingFilenames  = new List <String>();
            List <int>    address           = new List <int>();

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

            document.Expand();

            foreach (Document.File file in document.Files)
            {
                PhactoryHost.Database.Resource iResource = Host.GetResource(file.ResourceID);
                if (iResource == null)
                {
                    Host.Log("Unknown resource identifier : " + file.ResourceID);
                    return(false);
                }

                FileInfo iFileInfo = Host.GetFileInfo(iResource);

                resourceFilenames.Add(iFileInfo.FullName);
                paddingFilenames.Add(file.Pad256 ? "true" : "false");
                address.Add((file.SetAddress == false)?0:file.Address);
            }

            var compiler = new Phactory.Modules.BigFile.Compiler.BigFileCompiler();

            string resourceRelativePathNoExt = resource.RelativePath;

            resourceRelativePathNoExt = resourceRelativePathNoExt.Replace(".cpcbigfile", "");

            App.Controller.View.AppDoEvents();

            string baseFilename   = Host.MakeFullPath(resourceRelativePathNoExt);
            string headerFilename = Host.MakeFullPath(resourceRelativePathNoExt + ".H");

            if (!compiler.Compile(baseFilename, headerFilename, resourceFilenames, paddingFilenames, address, document.TruncateFiles, document.FilesInBank, document.BaseAddress))
            {
                return(false);
            }

            return(true);
        }
示例#2
0
        public bool Run(PhactoryHost.Database.Resource resource)
        {
            PhactoryHost.Database.Resource parentResource = Host.GetResource(resource.IdDependencies[0]);

            Document.Document document = Host.XMLRead <Document.Document>(Host.GetFileInfo(parentResource).FullName);

            string fileToExecute = "";

            foreach (Document.Item item in document.Items)
            {
                if (item.ExecAdress != 0)
                {
                    fileToExecute = item.AmsdosFilename;
                }
            }

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

            DSKFilename = DSKFilename.Replace(".cpcdsk", ".dsk");

            FileInfo DSKFileInfo = new FileInfo(DSKFilename);

            string WinAPEFullPath = Host.GetPluginsPath() + "WinAPE.exe";

            string arguments = "\"" + DSKFileInfo.FullName + "\" /A";

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

            return(Host.StartAndWaitAfterProcess(WinAPEFullPath, arguments, DSKFileInfo.DirectoryName));
        }
示例#3
0
        public bool Compile(PhactoryHost.Database.Resource resource)
        {
            FileInfo fileInfo = Host.GetFileInfo(resource);

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

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

            var compiler = new Phactory.Modules.Cloud.Compiler.CloudCompiler();

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

            foreach (Document.Item item in tempDocument.Items)
            {
                PhactoryHost.Database.Resource resItem = Host.GetResource(item.ResourceID);
                if (resItem == null)
                {
                    Host.Log("Unknown resource identifier : " + item.ResourceID);
                    return(false);
                }

                FileInfo resFileInfo    = Host.GetFileInfo(resItem);
                string   outputFilename = resFileInfo.FullName;

                if (Host.IsVerboseOutput())
                {
                    Host.Log(outputFilename);
                }

                string outputFilenameBin = outputFilename + ".bin";

                if (!compiler.WriteCloudBitmap(outputFilenameBin, item.CloudMaskData, item.CloudMaskWidth, item.CloudMaskHeight))
                {
                    return(false);
                }
            }

            return(true);
        }
示例#4
0
        private void WriteIdFileContent(PhactoryHost.Database.Resource resource, string destFilename)
        {
            var document = Host.XMLRead <Document.Document>(Host.GetFileInfo(resource).FullName);

            var title = resource.DisplayName.ToUpper().Replace(" ", "").Replace(".", "") + "H";

            var fileContent = String.Empty;

            fileContent += "// ----------------------------------------------------------------------------\n";
            fileContent += "#ifndef _" + title + "_TRACKFILEID_H_\n";
            fileContent += "#define _" + title + "_TRACKFILEID_H_\n";
            fileContent += "\n";

            fileContent += "// ----------------------------------------------------------------------------\n";
            int fileId = 1;

            foreach (var item in document.Items)
            {
                if (item.TrackLoaderItem)
                {
                    var itemResource = Host.GetResource(item.ResourceID);
                    var itemTitle    = itemResource.DisplayName.ToUpper().Replace(" ", "").Replace(".", "");

                    if (item.IsDuplicate)
                    {
                        fileContent += "#define " + itemTitle + "_TRACKFILEID_" + item.DuplicatedIndex + " " + fileId + "\n";
                    }
                    else
                    {
                        fileContent += "#define " + itemTitle + "_TRACKFILEID " + fileId + "\n";
                    }
                    fileId++;
                }
            }

            fileContent += "\n";

            fileContent += "// ----------------------------------------------------------------------------\n";
            fileContent += "#endif // _" + title + "_TRACKFILEID_H_";

            File.WriteAllText(destFilename, fileContent);
        }
示例#5
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);
        }
示例#6
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);
        }
示例#7
0
        public bool Compile(PhactoryHost.Database.Resource resource)
        {
            FileInfo fileInfo = Host.GetFileInfo(resource);

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

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

            string   CPCBitmapFilename = Host.GetFileInfo(resource).FullName;
            FileInfo CPCBitmapFileInfo = new FileInfo(CPCBitmapFilename);

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

            var CPCBitmapFilenamePalette = CPCBitmapFilename + ".palette";

            if (WritePalette(tempDocument, CPCBitmapFilenamePalette) == false)
            {
                return(false);
            }

            var CPCBitmapFilenameFirmwarePalette = CPCBitmapFilename + ".firmwarePalette";

            if (WriteFirmwarePalette(tempDocument, CPCBitmapFilenameFirmwarePalette) == false)
            {
                return(false);
            }

            string destFilenameH = Host.GetFileInfo(resource).FullName + ".info.h";
            var    title         = resource.DisplayName.ToUpper().Replace(" ", "").Replace(".", "") + "H";

            var fileContent = String.Empty;

            fileContent += "// ----------------------------------------------------------------------------\n";
            fileContent += "#ifndef _" + title + "_INFO_H_\n";
            fileContent += "#define _" + title + "_INFO_H_\n";
            fileContent += "\n";

            fileContent += "// ----------------------------------------------------------------------------\n";

            List <Document.Item> items = new List <Document.Item>();
            bool isGroup = false;

            foreach (Document.Item item in tempDocument.Items)
            {
                if (item.IsGroupDelimiter)
                {
                    if (isGroup)
                    {
                        items.Add(item);
                        isGroup = false;
                    }
                    else
                    {
                        isGroup = true;
                    }
                }
                if (isGroup)
                {
                    items.Add(item);
                }
            }
            isGroup = false;
            int startIndex = -1;
            List <Document.Item> resolvedItems = new List <Document.Item>();

            for (int iItem = 0; iItem < tempDocument.Items.Count; iItem++)
            {
                Document.Item item     = tempDocument.Items[iItem];
                Document.Item prevItem = null;

                if (item.IsGroupDelimiter)
                {
                    if (isGroup)
                    {
                        prevItem = tempDocument.Items[iItem - 2];
                        isGroup  = false;
                    }
                    else
                    {
                        isGroup    = true;
                        startIndex = iItem;
                    }
                }

                if (isGroup)
                {
                    if (iItem == startIndex)
                    {
                        prevItem = tempDocument.Items[startIndex + items.Count - 1 - 1];
                    }
                    else
                    if (iItem == (startIndex + 1))
                    {
                        prevItem = tempDocument.Items[startIndex + items.Count - 1];
                    }
                    else
                    {
                        prevItem = tempDocument.Items[iItem - 2];
                    }
                }

                resolvedItems.Add(prevItem);
            }

            for (int iItem = 0; iItem < tempDocument.Items.Count; iItem++)
            {
                App.Controller.View.AppDoEvents();

                Document.Item item = tempDocument.Items[iItem];

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

                FileInfo resFileInfo    = Host.GetFileInfo(resItem);
                string   outputFilename = resFileInfo.FullName;

                if (Host.IsVerboseOutput())
                {
                    Host.Log(outputFilename);
                }

                bool useMask = false;
                if (item.UseMaskType == Document.UseMaskType.NoMask)
                {
                }
                else
                if (item.UseMaskType == Document.UseMaskType.ColorMask)
                {
                    useMask = true;
                }
                else
                if (item.UseMaskType == Document.UseMaskType.BitmapMask)
                {
                    useMask = true;
                }

                var itemResource = Host.GetResource(item.ResourceID);
                var itemTitle    = itemResource.DisplayName.ToUpper().Replace(" ", "").Replace(".", "");

                if (item.IsFade)
                {
                    for (int iTargetItem = 0; iTargetItem < tempDocument.Items.Count; iTargetItem++)
                    {
                        var targetItem = tempDocument.Items[iTargetItem];

                        if (targetItem.ResourceID == item.MaskFadeResourceID)
                        {
                            var targetItemResource = Host.GetResource(targetItem.ResourceID);

                            string outputFadeFilename = outputFilename + ".fadePalette";

                            if (!WriteFadePalette(tempDocument, outputFadeFilename, item, targetItem))
                            {
                                return(false);
                            }

                            break;
                        }
                    }
                }
                else if (item.Type == Document.ItemType.FullScreenBitmap)
                {
                    string outputTopFilename    = outputFilename + ".topBin";
                    string outputBottomFilename = outputFilename + ".bottomBin";

                    var bitmapCompiler = BitmapCompiler.CreateCompiler(tempDocument.VideoMode);
                    if (!bitmapCompiler.WriteFullscreenBitmap(outputTopFilename,
                                                              outputBottomFilename,
                                                              item.IsFullScreenTitle,
                                                              (byte)item.MaskPenIndex,
                                                              item.IntermediateImage.Width,
                                                              item.IntermediateImage.Height,
                                                              item.IntermediateImage.Data,
                                                              (byte)tempDocument.StartIndex))
                    {
                        return(false);
                    }

                    fileContent += "#define " + itemTitle + "_FSBITMAP_HEIGHT " + item.IntermediateImage.Height + "\n";
                    fileContent += "#define " + itemTitle + "_FSBITMAP_BYTEWIDTH " + item.IntermediateImage.Width / 2 + "\n";
                    fileContent += "#define " + itemTitle + "_FSBITMAP_SIZE " + (item.IntermediateImage.Height / 2) * (item.IntermediateImage.Width / 2) + "\n";
                }
                else if (item.Type == Document.ItemType.Font)
                {
                    string outputFontFilename = outputFilename + ".font";

                    var bitmapCompiler = BitmapCompiler.CreateCompiler(tempDocument.VideoMode);
                    if (!bitmapCompiler.WriteFont(outputFontFilename, item.FontAlignOnCharaterLine, item.FontCharWidthInBytes,
                                                  item.IntermediateImage.Width,
                                                  item.IntermediateImage.Height,
                                                  item.IntermediateImage.Data,
                                                  (byte)tempDocument.StartIndex))
                    {
                        return(false);
                    }

                    fileContent += "#define " + itemTitle + "_FONT_HEIGHT " + item.IntermediateImage.Height + "\n";
                    fileContent += "#define " + itemTitle + "_FONT_BYTEWIDTH " + item.FontCharWidthInBytes + "\n";
                    fileContent += "#define " + itemTitle + "_FONT_CHARCOUNT " + ((item.IntermediateImage.Width / 4) / item.FontCharWidthInBytes) + "\n";
                }
                else if (
                    (item.Type == Document.ItemType.SpriteFullScreen) ||
                    (item.Type == Document.ItemType.SpriteRawData) ||
                    (item.Type == Document.ItemType.SpriteScreenData) ||
                    (item.Type == Document.ItemType.SpriteData) ||
                    (item.Type == Document.ItemType.SpriteOpcodes) ||
                    (item.Type == Document.ItemType.Font))
                {
                    string outputSpriteBitplan1Filename = "";
                    string outputSpriteBitplan2Filename = "";

                    string outputCloudSpriteBitplan1Filename = "";

                    int spriteType = 0;

                    if (item.Type == Document.ItemType.SpriteRawData)
                    {
                        outputSpriteBitplan1Filename = outputFilename + ".sprRawData1";
                        outputSpriteBitplan2Filename = outputFilename + ".sprRawData2";

                        if (item.IsCloudSprite)
                        {
                            outputCloudSpriteBitplan1Filename = outputFilename + ".cloudSprite.sprRawData1";
                        }

                        spriteType = 0;
                    }
                    else if (item.Type == Document.ItemType.SpriteData)
                    {
                        outputSpriteBitplan1Filename = outputFilename + ".sprData1";
                        outputSpriteBitplan2Filename = outputFilename + ".sprData2";

                        spriteType = 1;
                    }
                    else if (item.Type == Document.ItemType.SpriteScreenData)
                    {
                        outputSpriteBitplan1Filename = outputFilename + ".sprScrData1";
                        outputSpriteBitplan2Filename = outputFilename + ".sprScrData2";

                        spriteType = 3;
                    }
                    else if (item.Type == Document.ItemType.SpriteOpcodes)
                    {
                        outputSpriteBitplan1Filename = outputFilename + ".sprZ801";
                        outputSpriteBitplan2Filename = outputFilename + ".sprZ802";

                        spriteType = 2;
                    }
                    else if (item.Type == Document.ItemType.SpriteFullScreen)
                    {
                        outputSpriteBitplan1Filename = outputFilename + ".sprFullScreen";
                        outputSpriteBitplan2Filename = String.Empty;

                        spriteType = 4;
                    }

                    int[] diffData = null;
                    if (resolvedItems[iItem] != null)
                    {
                        diffData = resolvedItems[iItem].IntermediateImage.Data;
                    }

                    var bitmapCompiler = BitmapCompiler.CreateCompiler(tempDocument.VideoMode);
                    if (!bitmapCompiler.WriteSprite(outputSpriteBitplan1Filename,
                                                    outputSpriteBitplan2Filename,
                                                    item.IntermediateImage.Width,
                                                    item.IntermediateImage.Height,
                                                    item.IntermediateImage.Data,
                                                    item.IntermediateImage.BackgroundData,
                                                    spriteType,
                                                    useMask,
                                                    item.IntermediateImage.MaskData,
                                                    tempDocument.StartIndex,
                                                    item.MergePosX,
                                                    item.MergePosY,
                                                    item.IsCloudSprite,
                                                    outputCloudSpriteBitplan1Filename,
                                                    item.IntermediateImage.CloudData,
                                                    item.IntermediateImage.CloudWidth,
                                                    item.IntermediateImage.CloudHeight,
                                                    diffData
                                                    ))
                    {
                        return(false);
                    }

                    fileContent += "#define " + itemTitle + "_SPR_HEIGHT " + bitmapCompiler.GetLastHeight() + "\n";

                    if (String.IsNullOrEmpty(outputSpriteBitplan2Filename))
                    {
                        fileContent += "#define " + itemTitle + "_SPR_BYTEWIDTH " + bitmapCompiler.GetLastWidthBytesBitplan1() + "\n";
                        fileContent += "#define " + itemTitle + "_SPR_SIZE 0x" + String.Format("{0:X4}", bitmapCompiler.GetLastWidthBytesBitplan1() * bitmapCompiler.GetLastHeight()) + "\n";
                    }
                    else
                    {
                        fileContent += "#define " + itemTitle + "_SPR_BYTEWIDTH1 " + bitmapCompiler.GetLastWidthBytesBitplan1() + "\n";
                        fileContent += "#define " + itemTitle + "_SPR_BYTEWIDTH2 " + bitmapCompiler.GetLastWidthBytesBitplan2() + "\n";
                        fileContent += "#define " + itemTitle + "_SPR_SIZE1 0x" + String.Format("{0:X4}", bitmapCompiler.GetLastWidthBytesBitplan1() * bitmapCompiler.GetLastHeight()) + "\n";
                        fileContent += "#define " + itemTitle + "_SPR_SIZE2 0x" + String.Format("{0:X4}", bitmapCompiler.GetLastWidthBytesBitplan2() * bitmapCompiler.GetLastHeight()) + "\n";
                    }

                    if (item.IsMerge)
                    {
                        fileContent += "#define " + itemTitle + "_MERGE_POSX " + item.MergePosX + "\n";
                        fileContent += "#define " + itemTitle + "_MERGE_POSY " + item.MergePosY + "\n";
                    }
                }
            }

            fileContent += "\n";

            fileContent += "// ----------------------------------------------------------------------------\n";
            fileContent += "#endif // _" + title + "_INFO_H_";

            File.WriteAllText(destFilenameH, fileContent);

            return(true);
        }
示例#8
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);
        }
示例#9
0
        public bool Compile(PhactoryHost.Database.Resource resource)
        {
            FileInfo fileInfo = Host.GetFileInfo(resource);

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

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

            var compiler = new Phactory.Modules.RawBitmap.Compiler.RawCompiler();

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

            List <string> outputFilenames = new List <string>();

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

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

                FileInfo resFileInfo    = Host.GetFileInfo(resItem);
                string   outputFilename = resFileInfo.FullName;

                if (Host.IsVerboseOutput())
                {
                    Host.Log(outputFilename);
                }

                Document.ItemType type = item.Type;

                if (type == CPCRawBitmap.Document.ItemType.Raw)
                {
                    string outputTopFilename = outputFilename + ".rawBin";

                    if (!compiler.WriteRawBinFile(outputTopFilename,
                                                  item.IntermediateImage.Width,
                                                  item.IntermediateImage.Height,
                                                  item.IntermediateImage.Data,
                                                  false))
                    {
                        return(false);
                    }
                }
                else if (type == CPCRawBitmap.Document.ItemType.VerticalRaw)
                {
                    string outputTopFilename = outputFilename + ".verticalRawBin";

                    if (!compiler.WriteRawBinFile(outputTopFilename,
                                                  item.IntermediateImage.Width,
                                                  item.IntermediateImage.Height,
                                                  item.IntermediateImage.Data,
                                                  true))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }