private bool CreateImage(string[] args) { BootImage bootImg = new BootImage(); string framePath = null; string titlePath = null; string released = null; string players = null; string outPath = null; for (int i = 0; i < args.Length; i++) { switch (args[i]) { case "create-image": break; case "-frame": if (i + 1 < args.Length && framePath == null) { framePath = args[++i]; break; } else { Cll.Log.WriteLine("Error in the \"-frame\" option."); return(false); } case "-title": if (i + 1 < args.Length && titlePath == null) { titlePath = args[++i]; break; } else { Cll.Log.WriteLine("Error in the \"-title\" option."); return(false); } case "-name": if (i + 1 < args.Length && bootImg.NameLine1 == null) { bootImg.NameLine1 = args[++i]; bootImg.NameLine2 = ""; bootImg.Longname = false; break; } else { Cll.Log.WriteLine("Error in the \"-name\" option."); return(false); } case "-longname": if (i + 2 < args.Length && bootImg.NameLine1 == null) { bootImg.NameLine1 = args[++i]; bootImg.NameLine2 = args[++i]; bootImg.Longname = true; break; } else { Cll.Log.WriteLine("Error in the \"-longname\" option."); return(false); } case "-r": if (i + 1 < args.Length && released == null) { released = args[++i]; break; } else { Cll.Log.WriteLine("Error in the \"-r\" option."); return(false); } case "-p": if (i + 1 < args.Length && players == null) { players = args[++i]; break; } else { Cll.Log.WriteLine("Error in the \"-p\" option."); return(false); } case "-out": if (i + 1 < args.Length && outPath == null) { outPath = args[++i]; break; } else { Cll.Log.WriteLine("Error in the \"-out\" option."); return(false); } default: Cll.Log.WriteLine("Invalid option \"" + args[i] + "\"."); return(false); } } if (framePath != null && !File.Exists(framePath)) { Cll.Log.WriteLine("The frame image \"" + framePath + "\" not exists."); return(false); } if (titlePath != null && !File.Exists(titlePath)) { Cll.Log.WriteLine("The title screen \"" + titlePath + "\" not exists."); return(false); } if (released != null) { try { bootImg.Released = Convert.ToInt32(released); if (bootImg.Released < 1996) { Cll.Log.WriteLine("The year of release is less than 1996."); return(false); } } catch { Cll.Log.WriteLine("The year of release is not an integer."); return(false); } } if (players != null) { try { bootImg.Players = Convert.ToInt32(players); if (bootImg.Players < 1 || bootImg.Players > 4) { Cll.Log.WriteLine("The number of players must be between 1 and 4."); return(false); } } catch { Cll.Log.WriteLine("The number of players is not an integer."); return(false); } } if (outPath != null) { if (!Directory.Exists(outPath)) { Cll.Log.WriteLine("The \"" + outPath + "\" folder not exist."); return(false); } } else { outPath = Environment.CurrentDirectory; } outPath += "\\image.png"; Cll.Log.WriteLine("Creating image ----------------------------------------------------------------"); if (titlePath != null) { Cll.Log.WriteLine("title: " + titlePath); } if (framePath != null) { Cll.Log.WriteLine("frame: " + framePath); } if (bootImg.NameLine1 != "") { if (bootImg.NameLine2 == "") { Cll.Log.WriteLine("name: " + bootImg.NameLine1); } else { Cll.Log.WriteLine("longname:\n" + bootImg.NameLine1 + "\n" + bootImg.NameLine2); } } if (released != null) { Cll.Log.WriteLine("released: " + released); } if (players != null) { Cll.Log.WriteLine("players: " + players); } if (outPath != null) { Cll.Log.WriteLine("out: " + outPath); } System.Drawing.Bitmap image = null; try { if (framePath != null) { bootImg.Frame = new System.Drawing.Bitmap(framePath); } if (titlePath != null) { bootImg.TitleScreen = new System.Drawing.Bitmap(titlePath); } image = bootImg.Create(); image.Save(outPath, System.Drawing.Imaging.ImageFormat.Png); image.Dispose(); return(true); } catch { return(false); } finally { bootImg.Dispose(); if (image != null) { image.Dispose(); } } }
private bool InjectImages() { string currentDir = Environment.CurrentDirectory; Bitmap bootTvImg; Bitmap bootDrcImg; Bitmap iconImg; Bitmap tmp; Graphics g; try { Cll.Log.WriteLine("Creating bitmaps."); if (BootTvPath != null) { tmp = new Bitmap(BootTvPath); } else { tmp = BootTvImg.Create(); } bootTvImg = new Bitmap(1280, 720, PixelFormat.Format24bppRgb); g = Graphics.FromImage(bootTvImg); g.DrawImage(tmp, new Rectangle(0, 0, 1280, 720)); g.Dispose(); tmp.Dispose(); if (BootDrcPath != null) { tmp = new Bitmap(BootDrcPath); } else { tmp = BootDrcImg.Create(); } bootDrcImg = new Bitmap(854, 480, PixelFormat.Format24bppRgb); g = Graphics.FromImage(bootDrcImg); g.DrawImage(tmp, new Rectangle(0, 0, 854, 480)); g.Dispose(); tmp.Dispose(); if (IconPath != null) { tmp = new Bitmap(IconPath); } else { tmp = IconImg.Create(); } iconImg = new Bitmap(128, 128, PixelFormat.Format32bppArgb); g = Graphics.FromImage(iconImg); g.DrawImage(tmp, new Rectangle(0, 0, 128, 128)); g.Dispose(); tmp.Dispose(); Cll.Log.WriteLine("Bitmaps created."); } catch { Cll.Log.WriteLine("Error creating bitmaps."); return(false); } if (!NusContent.ConvertToTGA(bootTvImg, currentDir + "\\base\\meta\\bootTvTex.tga")) { Cll.Log.WriteLine("Error creating \"bootTvTex.tga\" file."); return(false); } if (!NusContent.ConvertToTGA(bootDrcImg, currentDir + "\\base\\meta\\bootDrcTex.tga")) { Cll.Log.WriteLine("Error creating \"bootDrcTex.tga\" file."); return(false); } if (!NusContent.ConvertToTGA(iconImg, currentDir + "\\base\\meta\\iconTex.tga")) { Cll.Log.WriteLine("Error creating \"iconTex.tga\" file."); return(false); } Cll.Log.WriteLine("Injected TGA files."); return(true); }