OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / Program.cs
1 using System;\r
2 using System.Collections.Generic;\r
3 using System.Collections.Specialized;\r
4 using System.ComponentModel;\r
5 using System.Data;\r
6 using System.Drawing;\r
7 using System.Text;\r
8 using System.Windows.Forms;\r
9 using System.Net;\r
10 using System.IO;\r
11 using System.Diagnostics;\r
12 using System.Threading;\r
13 using System.Runtime.InteropServices;\r
14 \r
15 \r
16 namespace Handbrake\r
17 {\r
18     static class Program\r
19     {\r
20         /// <summary>\r
21         /// The main entry point for the application.\r
22         /// </summary>\r
23         [STAThread]\r
24         static void Main()\r
25         {\r
26 \r
27             // Check the system meets the system requirements.\r
28             Boolean launch = true;\r
29             try\r
30             {\r
31                 // Make sure the screen resolution is not below 1024x768\r
32                 System.Windows.Forms.Screen scr = System.Windows.Forms.Screen.PrimaryScreen;\r
33                 if ((scr.Bounds.Width < 1024) || (scr.Bounds.Height < 720))\r
34                 {\r
35                     MessageBox.Show("Your system does not meet the minimum requirements for HandBrake. \n" + "Your screen is running at: " + scr.Bounds.Width.ToString() + "x" + scr.Bounds.Height.ToString() + " \nScreen resolution is too Low. Must be 1024x720 or greater", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
36                     launch = false;\r
37                 }\r
38 \r
39                 // Make sure the system has enough RAM. 384MB or greater\r
40                 uint memory = MemoryCheck.CheckMemeory();\r
41                 memory = memory / 1024 / 1024;\r
42 \r
43                 if (memory < 256)\r
44                 {\r
45                     MessageBox.Show("Your system does not meet the minimum requirements for HandBrake. \n Insufficient RAM. 384MB or greater required. You have: " + memory.ToString() + "MB", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
46                     launch = false;\r
47                 }\r
48             }\r
49             catch (Exception exc)\r
50             {\r
51                 MessageBox.Show("frmMain.cs - systemCheck() " + exc.ToString());\r
52             }\r
53 \r
54 \r
55             // Either Launch or Close the Application\r
56             if (launch == true)\r
57             {\r
58                 Application.EnableVisualStyles();\r
59                 Application.SetCompatibleTextRenderingDefault(false);\r
60                 Application.Run(new frmMain());\r
61             }\r
62             else\r
63             {\r
64                 Application.Exit();\r
65             }\r
66         }\r
67     }\r
68 \r
69     class MemoryCheck\r
70     {\r
71         public struct MEMORYSTATUS\r
72         {\r
73             public UInt32 dwLength;\r
74             public UInt32 dwMemoryLoad;\r
75             public UInt32 dwTotalPhys; // Used\r
76             public UInt32 dwAvailPhys;\r
77             public UInt32 dwTotalPageFile;\r
78             public UInt32 dwAvailPageFile;\r
79             public UInt32 dwTotalVirtual;\r
80             public UInt32 dwAvailVirtual;\r
81             // Aditional Varibles left in for future usage (JIC)\r
82         }\r
83 \r
84         [DllImport("kernel32.dll")]\r
85         public static extern void GlobalMemoryStatus\r
86         (\r
87             ref MEMORYSTATUS lpBuffer\r
88         );\r
89 \r
90         public static uint CheckMemeory()\r
91         {\r
92             // Call the native GlobalMemoryStatus method\r
93             // with the defined structure.\r
94             MEMORYSTATUS memStatus = new MEMORYSTATUS();\r
95             GlobalMemoryStatus(ref memStatus);\r
96 \r
97             uint MemoryInfo = memStatus.dwTotalPhys;\r
98 \r
99             return MemoryInfo;\r
100         }\r
101     }\r
102 }