private void WriteIdFile(PhactoryHost.Database.Resource resource) { var destFilename = Host.GetFileInfo(resource).FullName + ".h"; App.Controller.UserConfig.AddExistingResourceFullPath = destFilename; string relativePath = StringHelper.MakeRelativePath(destFilename); PhactoryHost.Database.Resource idResource = Host.GuessResource(new FileInfo(destFilename)); if (idResource == null) { idResource = new PhactoryHost.Database.Resource(); idResource.Id = App.Controller.Entities.CreateNewResourceId(); idResource.DisplayName = new FileInfo(destFilename).Name; idResource.RelativePath = relativePath; App.Controller.Entities.AddResource(idResource); App.Controller.CreateNewResource(idResource); var project = Host.GetEntities(); Node folderNode = null; project.GetParentFolderTreeNode(project.TreeNode, ref folderNode, resource); if (folderNode != null) { Node childTreeNode = new Node(); childTreeNode.IsFolder = false; childTreeNode.ResourceId = idResource.Id; folderNode.ChildNodes.Add(childTreeNode); } App.Controller.SaveProject(); Host.RefreshDB(); } File.Delete(destFilename); WriteIdFileContent(resource, destFilename); Host.Log(idResource.DisplayName + " written"); }
public bool Compile(PhactoryHost.Database.Resource resource) { FileInfo fileInfo = Host.GetFileInfo(resource); if (fileInfo == null) { return(false); } if (!IsResourceSupported(resource)) { return(false); } if (fileInfo.Extension.ToLower() == ".asm") { return(CompileASM(resource)); } if (fileInfo.Extension.ToLower() != ".c") { // only compiles .C files (ignore .H) return(true); } // check that .c file is not an include from an other .c file // (in that case, skip compile) var dependencyResources = Host.GetDependencyResources(resource); bool hasAsmDependentResource = false; foreach (PhactoryHost.Database.Resource resourceDependency in dependencyResources) { FileInfo parentFileInfo = Host.GetFileInfo(resourceDependency); if (parentFileInfo.Extension.ToLower() == ".asm") { hasAsmDependentResource = true; } } if (!hasAsmDependentResource) { foreach (PhactoryHost.Database.Resource resourceDependency in dependencyResources) { FileInfo parentFileInfo = Host.GetFileInfo(resourceDependency); if (parentFileInfo.Extension.ToLower() == ".c") { return(true); } } } string asmFilename = fileInfo.FullName.ToLower().Replace(".c", ".asm"); string exeFullPath = Host.GetPluginsPath() + "SDCC\\bin\\SDCC.EXE"; string arguments = "-mz80 -S --no-std-crt0 \"" + fileInfo.FullName + "\" --disable-warning 59 --disable-warning 154 --disable-warning 110 --disable-warning 84 --disable-warning 112"; bool isOK = Host.StartProcess(exeFullPath, arguments, fileInfo.DirectoryName, true); if (isOK) { string standardOutput = Host.GetLastErrorOutput(); standardOutput = standardOutput.Replace("\\/", "\\"); string[] lineOutputs = standardOutput.Split('\n'); foreach (string iLineOutput in lineOutputs) { string lineOutput = iLineOutput; if (!lineOutput.Contains("In file included from") && !lineOutput.Contains("missing terminating") && !lineOutput.Contains("z80instructionSize()") && (lineOutput.Length > 4)) { int filenameLength = lineOutput.IndexOf(":", 3); if (filenameLength != -1) { string filename = lineOutput.Substring(0, filenameLength); FileInfo lineFileInfo = new FileInfo(filename); PhactoryHost.Database.Resource lineResource = Host.GuessResource(lineFileInfo); if (lineResource != null) { lineOutput = lineOutput.Replace(filename, lineResource.DisplayName); } if (lineOutput.IndexOf("error") != -1) { isOK = false; Host.Log("\n" + lineOutput); Host.Log("\nCompilation failed with '" + resource.DisplayName + "' !"); break; } else /*if (lineOutput.IndexOf(": warning") != -1) * { * if (Host.IsVerboseOutput()) * { * Host.Log("\n" + lineOutput); * } * } * else*/ { Host.Log("\n" + lineOutput); } } else { Host.Log("\n" + lineOutput); } } } } if (isOK) { exeFullPath = Host.GetPluginsPath() + "SDCC2Pasmo.EXE"; arguments = "\"" + asmFilename + "\""; arguments += " \"" + asmFilename + ".maxam\""; isOK = Host.StartProcess(exeFullPath, arguments, fileInfo.DirectoryName, true); if (isOK) { string standardOutput = Host.GetLastStandardOutput(); bool errorFound = false; if (standardOutput.IndexOf("SDCC2Pasmo") != -1) { errorFound = true; } if (errorFound) { isOK = false; Host.Log("\nCompilation failed with '" + resource.DisplayName + "'..\nLog output:\n" + Host.GetLastStandardOutput()); } } File.Delete(asmFilename); var maxamFilename = asmFilename + ".maxam"; if (!File.Exists(maxamFilename)) { return(false); } if (isOK) { File.Move(maxamFilename, asmFilename); } } return(isOK); }