OSDN Git Service

a613eca658296ff10c30b39933905c59e3391f91
[handbrake-jp/handbrake-jp-git.git] / win / C# / Program.cs
1 /*  Program.cs \r
2         \r
3            This file is part of the HandBrake source code.\r
4            Homepage: <http://handbrake.m0k.org/>.\r
5            It may be used under the terms of the GNU General Public License. */\r
6 \r
7 using System;\r
8 using System.Collections.Generic;\r
9 using System.Collections.Specialized;\r
10 using System.ComponentModel;\r
11 using System.Data;\r
12 using System.Drawing;\r
13 using System.Text;\r
14 using System.Windows.Forms;\r
15 using System.Net;\r
16 using System.IO;\r
17 using System.Diagnostics;\r
18 using System.Threading;\r
19 using System.Runtime.InteropServices;\r
20 using System.Globalization;\r
21 \r
22 \r
23 namespace Handbrake\r
24 {\r
25     static class Program\r
26     {\r
27         /// <summary>\r
28         /// The main entry point for the application.\r
29         /// </summary>\r
30         [STAThread]\r
31         static void Main()\r
32         {\r
33             // Development Code Expiry.\r
34             // Remember to comment out on public release!!!\r
35             if (DateTime.Now > DateTime.Parse("2008/02/27", new CultureInfo("en-US"))) { MessageBox.Show("Sorry, This development build of Handbrake has expired."); return; } \r
36 \r
37             // Check the system meets the system requirements.\r
38             Boolean launch = true;\r
39             try\r
40             {\r
41                 // Make sure the screen resolution is not below 1024x768\r
42                 System.Windows.Forms.Screen scr = System.Windows.Forms.Screen.PrimaryScreen;\r
43                 if ((scr.Bounds.Width < 1024) || (scr.Bounds.Height < 720))\r
44                 {\r
45                     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
46                     launch = false;\r
47                 }\r
48 \r
49                 // Make sure the system has enough RAM. 384MB or greater\r
50                 uint memory = MemoryCheck.CheckMemeory();\r
51                 memory = memory / 1024 / 1024;\r
52 \r
53                 if (memory < 256)\r
54                 {\r
55                     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
56                     launch = false;\r
57                 }\r
58             }\r
59             catch (Exception exc)\r
60             {\r
61                 MessageBox.Show("frmMain.cs - systemCheck() " + exc.ToString());\r
62             }\r
63 \r
64             // Either Launch or Close the Application\r
65             if (launch == true)\r
66             {\r
67                 Application.EnableVisualStyles();\r
68                 Application.SetCompatibleTextRenderingDefault(false);\r
69                 Application.Run(new frmMain());\r
70             }\r
71             else\r
72             {\r
73                 Application.Exit();\r
74             }\r
75         }\r
76     }\r
77 \r
78     class MemoryCheck\r
79     {\r
80         public struct MEMORYSTATUS\r
81         {\r
82             public UInt32 dwLength;\r
83             public UInt32 dwMemoryLoad;\r
84             public UInt32 dwTotalPhys; // Used\r
85             public UInt32 dwAvailPhys;\r
86             public UInt32 dwTotalPageFile;\r
87             public UInt32 dwAvailPageFile;\r
88             public UInt32 dwTotalVirtual;\r
89             public UInt32 dwAvailVirtual;\r
90             // Aditional Varibles left in for future usage (JIC)\r
91         }\r
92 \r
93         [DllImport("kernel32.dll")]\r
94         public static extern void GlobalMemoryStatus\r
95         (\r
96             ref MEMORYSTATUS lpBuffer\r
97         );\r
98 \r
99         public static uint CheckMemeory()\r
100         {\r
101             // Call the native GlobalMemoryStatus method\r
102             // with the defined structure.\r
103             MEMORYSTATUS memStatus = new MEMORYSTATUS();\r
104             GlobalMemoryStatus(ref memStatus);\r
105 \r
106             uint MemoryInfo = memStatus.dwTotalPhys;\r
107 \r
108             return MemoryInfo;\r
109         }\r
110     }\r
111 }