Exemple #1
0
        private Overlay CreateOverlay(string bitmapFilePath)
        {
            bool   succes             = false;
            var    ov                 = new Overlay();
            var    fileDirectory      = Path.GetPathRoot(bitmapFilePath);
            var    fileName           = Path.GetFileName(bitmapFilePath);
            var    filenameWithoutExt = Path.GetFileNameWithoutExtension(bitmapFilePath);
            var    img8bitPath        = Path.Combine(Main.FolderOverlays, "img8bit.bmp");
            string bo1FilePath        = String.Empty;

            try
            {
                var temp  = new Bitmap(bitmapFilePath);
                var bm320 = new Bitmap(temp, new Size(320, 200));
                temp.Dispose();


                Bitmap img8bit = ConvertorTo8Bit.ConvertTo8bppFormat(bm320);


                if (File.Exists(img8bitPath))
                {
                    File.Delete(img8bitPath);
                }

                img8bit.Save(img8bitPath, System.Drawing.Imaging.ImageFormat.Bmp);


                string noConsole = "-noconsole ";
                string mountHD   = "-c \"mount c " + Main.FolderRoot + "\"";
                string switchToC = "-c \"c:\"";
                string switchDir = "-c \"cd Odyemu\"";
                string runBMR    = "-c \"BMPTORLE " + "C:\\Overlays\\" + "img8bit.bmp" + " " + "C:\\Overlays\\" + "output.BO1\"";
                string exit      = "-c \"exit\"";

                ProcessStartInfo dosBoxInfo = new ProcessStartInfo(Main.PathDosBox, noConsole + mountHD + switchToC + switchDir + runBMR + exit);
                // dosBoxInfo.WindowStyle = ProcessWindowStyle.Minimized;
                Process dosBoxProcess = new Process();
                dosBoxProcess.StartInfo = dosBoxInfo;
                dosBoxProcess.Start();

                System.Threading.Thread.Sleep(200);

                System.IntPtr   app_hwnd;
                WINDOWPLACEMENT wp = new WINDOWPLACEMENT();
                app_hwnd = dosBoxProcess.MainWindowHandle;
                GetWindowPlacement(app_hwnd, ref wp);
                wp.showCmd = 2;
                SetWindowPlacement(app_hwnd, ref wp);


                dosBoxProcess.WaitForExit();


                File.Delete(img8bitPath);


                bo1FilePath = Path.Combine(Main.FolderOverlays, "output.BO1");


                if (File.Exists(bo1FilePath))
                {
                    var      lastwrite = File.GetLastWriteTime(bo1FilePath);
                    TimeSpan g         = DateTime.Now - lastwrite;

                    if (g.Seconds < 5)
                    {
                        succes = true;
                    }
                }
                else
                {
                    succes = false;
                }

                if (succes)
                {
                    if (!File.Exists(Path.Combine(Main.FolderOverlays, fileName)))
                    {
                        File.Copy(bitmapFilePath, Path.Combine(Main.FolderOverlays, fileName));
                    }
                    ov.FileName  = fileName;
                    ov.Name      = filenameWithoutExt;
                    ov.Image     = new Bitmap(img8bit);
                    ov.Bo1       = File.ReadAllBytes(bo1FilePath);
                    ov.Cartridge = 1;
                    ov.Asociate  = false;
                    succes       = ov.Save();
                }


                img8bit.Dispose();
                bm320.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Cannot create Overlay \n" + ex.Message);
                return(null);
            }

            finally
            {
                if (File.Exists(bo1FilePath))
                {
                    File.Delete(bo1FilePath);
                }
            }

            return(ov);
        }
        public bool SetOpaqueColor(Color opaqueColor)
        {
            var  OroginalbitmapFilePath = Path.Combine(Main.FolderOverlays, FileName);
            bool succes = false;

            var    img8bitPath = Path.Combine(Main.FolderOverlays, "parse.bmp");
            string bo1FilePath = String.Empty;

            try
            {
                var temp = new Bitmap(OroginalbitmapFilePath);
                var bm   = new Bitmap(temp, new Size(320, 200));
                temp.Dispose();

                if (opaqueColor != null)
                {
                    bm.SetPixel(0, 0, opaqueColor);
                }


                Bitmap img8bit = ConvertorTo8Bit.ConvertTo8bppFormat(bm);



                //img8bit.Save(Path.Combine(Main.FolderOverlays, "8bit.bmp"));
                if (File.Exists(img8bitPath))
                {
                    File.Delete(img8bitPath);
                }

                img8bit.Save(img8bitPath, System.Drawing.Imaging.ImageFormat.Bmp);


                string noConsole = "-noconsole ";
                string mountHD   = "-c \"mount c " + Main.FolderRoot + "\"";
                string switchToC = "-c \"c:\"";
                string switchDir = "-c \"cd Odyemu\"";
                string runBMR    = "-c \"BMPTORLE " + "C:\\Overlays\\" + "parse.bmp" + " " + "C:\\Overlays\\" + "output.BO1\"";
                string exit      = "-c \"exit\"";

                ProcessStartInfo dosBoxInfo = new ProcessStartInfo(Main.PathDosBox, noConsole + mountHD + switchToC + switchDir + runBMR + exit);
                dosBoxInfo.CreateNoWindow  = true;
                dosBoxInfo.WindowStyle     = ProcessWindowStyle.Minimized;
                dosBoxInfo.UseShellExecute = false;
                dosBoxInfo.ErrorDialog     = false;

                dosBoxInfo.WindowStyle = ProcessWindowStyle.Minimized;
                Process dosBoxProcess = new Process();
                dosBoxProcess.StartInfo = dosBoxInfo;
                dosBoxProcess.Start();


                System.Threading.Thread.Sleep(200);

                System.IntPtr   app_hwnd;
                WINDOWPLACEMENT wp = new WINDOWPLACEMENT();
                app_hwnd = dosBoxProcess.MainWindowHandle;
                GetWindowPlacement(app_hwnd, ref wp);
                wp.showCmd = 2;
                SetWindowPlacement(app_hwnd, ref wp);



                dosBoxProcess.WaitForExit();


                File.Delete(img8bitPath);


                bo1FilePath = Path.Combine(Main.FolderOverlays, "output.BO1");
                var lastwrite = File.GetLastWriteTime(bo1FilePath);

                if (File.Exists(bo1FilePath))
                {
                    TimeSpan g = DateTime.Now - lastwrite;
                    if (g.Seconds < 5)
                    {
                        succes = true;
                    }
                }
                else
                {
                    succes = false;
                }

                if (succes)
                {
                    Bo1   = File.ReadAllBytes(bo1FilePath);
                    Image = new Bitmap(img8bit);
                    //File.Copy(bitmapFilePath, Path.Combine(Main.FolderOverlays, fileName));
                    //ov.Name = filenameWithoutExt;
                    //ov.Image = new Bitmap(img8bit);
                    //ov.Bo1 = File.ReadAllBytes(bo1FilePath);
                    //ov.Cartridge = 1;
                    //ov.Asociate = false;
                    //succes = ov.Save();
                }


                img8bit.Dispose();
                bm.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            finally
            {
                if (File.Exists(bo1FilePath))
                {
                    File.Delete(bo1FilePath);
                }
            }

            Save();
            return(succes);
        }