예제 #1
0
        static void Main(string[] args)
        {
            // First: Set working folder to the path of executable.
            var fi = new FileInfo(Application.ExecutablePath);

            Directory.SetCurrentDirectory(fi.Directory.FullName);
            // Prevent brave users from running this app from Windows folder.
            var winFolder = Environment.GetFolderPath(Environment.SpecialFolder.Windows);

            if (fi.FullName.StartsWith(winFolder, StringComparison.OrdinalIgnoreCase))
            {
                MessageBox.Show("Running from Windows folder is not allowed!\r\nPlease run this program from another folder.", "Windows Folder", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            //var x = @"c:\Program Files\X360CE\x360ce.ini";
            //if (File.Exists(x))
            //{
            //    var rights = System.Security.AccessControl.FileSystemRights.Modify;
            //    var users = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null);
            //    // Check if users in non elevated mode have rights to modify the file.
            //    var hasRights = JocysCom.ClassLibrary.Security.PermissionHelper.HasRights(x, rights, users, false);
            //    if (!hasRights && JocysCom.ClassLibrary.Win32.WinAPI.IsElevated())
            //    {
            //        // Allow users to modify file when in non elevated mode.
            //        JocysCom.ClassLibrary.Security.PermissionHelper.SetRights(x, rights, users);
            //        hasRights = JocysCom.ClassLibrary.Security.PermissionHelper.HasRights(x, rights, users, false);
            //    }
            //}

            // IMPORTANT: Make sure this class don't have any static references to x360ce.Engine library or
            // program tries to load x360ce.Engine.dll before AssemblyResolve event is available and fails.
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
            if (IsDebug)
            {
                StartApp(args);
                return;
            }
            try
            {
                StartApp(args);
            }
            catch (Exception ex)
            {
                var message = ExceptionToText(ex);
                var box     = new Controls.MessageBoxForm();
                if (message.Contains("Could not load file or assembly 'Microsoft.DirectX"))
                {
                    message += "===============================================================\r\n";
                    message += "You can click the link below to download Microsoft DirectX.";
                    box.MainLinkLabel.Text    = "http://www.microsoft.com/en-us/download/details.aspx?id=35";
                    box.MainLinkLabel.Visible = true;
                }
                var result = box.ShowForm(message, "Exception!", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                if (result == DialogResult.Cancel)
                {
                    Application.Exit();
                }
            }
        }
예제 #2
0
 static void Main(string[] args)
 {
     // IMPORTANT: Make sure this class don't have any static references to x360ce.Engine library or
     // program tries to load x360ce.Engine.dll before AssemblyResolve event is available and fails.
     AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
     if (IsDebug)
     {
         StartApp(args);
         return;
     }
     try
     {
         StartApp(args);
     }
     catch (Exception ex)
     {
         var message = ExceptionToText(ex);
         var box     = new Controls.MessageBoxForm();
         if (message.Contains("Could not load file or assembly 'Microsoft.DirectX"))
         {
             message += "===============================================================\r\n";
             message += "You can click the link below to download Microsoft DirectX.";
             box.MainLinkLabel.Text    = "http://www.microsoft.com/en-us/download/details.aspx?id=35";
             box.MainLinkLabel.Visible = true;
         }
         var result = box.ShowForm(message, "Exception!", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
         if (result == DialogResult.Cancel)
         {
             Application.Exit();
         }
     }
 }
예제 #3
0
 static void Main(string[] args)
 {
     if (IsDebug)
     {
         StartApp(args);
         return;
     }
     try
     {
         StartApp(args);
     }
     catch (Exception ex)
     {
         var message = AppHelper.ExceptionToText(ex);
         var box     = new Controls.MessageBoxForm();
         if (message.Contains("Could not load file or assembly 'Microsoft.DirectX"))
         {
             message += "===============================================================\r\n";
             message += "You can click the link below to download Microsoft DirectX.";
             box.MainLinkLabel.Text    = "http://www.microsoft.com/en-us/download/details.aspx?id=35";
             box.MainLinkLabel.Visible = true;
         }
         var result = box.ShowForm(message, "Exception!", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
         if (result == DialogResult.Cancel)
         {
             Application.Exit();
         }
     }
 }
예제 #4
0
		static void Main(string[] args)
		{
			try
			{
				//var fi = new FileInfo(Application.ExecutablePath);
				//Directory.SetCurrentDirectory(fi.Directory.FullName);
				// IMPORTANT: Make sure this method don't have any static references to x360ce.Engine library or
				// program tries to load x360ce.Engine.dll before AssemblyResolve event is available and fails.
				AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
				if (!RuntimePolicyHelper.LegacyV2RuntimeEnabledSuccessfully)
				{
					// Failed to enable useLegacyV2RuntimeActivationPolicy at runtime.
				}
				Application.EnableVisualStyles();
				Application.SetCompatibleTextRenderingDefault(false);
				// Requires System.Configuration.Installl reference.
				var ic = new System.Configuration.Install.InstallContext(null, args);
				if (ic.Parameters.ContainsKey("Settings"))
				{
					OpenSettingsFolder(Application.UserAppDataPath);
					OpenSettingsFolder(Application.CommonAppDataPath);
					OpenSettingsFolder(Application.LocalUserAppDataPath);
					return;
				}
				if (!CheckSettings()) return;
				//Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
				MainForm.Current = new MainForm();
				if (ic.Parameters.ContainsKey("Exit"))
				{
					MainForm.Current.BroadcastMessage(MainForm.wParam_Close);
					return;
				}
				if (!IsOneCopyRunningAlready())
				{
					Application.Run(MainForm.Current);
				}
			}
			catch (Exception ex)
			{
				var message = "";
				AddExceptionMessage(ex, ref message);
				if (ex.InnerException != null) AddExceptionMessage(ex.InnerException, ref message);
				var box = new Controls.MessageBoxForm();
				if (message.Contains("Could not load file or assembly 'Microsoft.DirectX"))
				{
					message += "===============================================================\r\n";
					message += "You can click the link below to download Microsoft DirectX.";
					box.MainLinkLabel.Text = "http://www.microsoft.com/en-us/download/details.aspx?id=35";
					box.MainLinkLabel.Visible = true;
				}
				var result = box.ShowForm(message, "Exception!", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
				if (result == DialogResult.Cancel) Application.Exit();
			}
		}
예제 #5
0
파일: Program.cs 프로젝트: zamliage/x360ce
        static void Main(string[] args)
        {
            // First: Set working folder to the path of executable.
            var fi = new FileInfo(Application.ExecutablePath);

            Directory.SetCurrentDirectory(fi.Directory.FullName);
            // Prevent brave users from running this application from Windows folder.
            var winFolder = Environment.GetFolderPath(Environment.SpecialFolder.Windows);

            if (fi.FullName.StartsWith(winFolder, StringComparison.OrdinalIgnoreCase))
            {
                MessageBox.Show("Running from Windows folder is not allowed!\r\nPlease run this program from another folder.", "Windows Folder", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            // IMPORTANT: Make sure this class don't have any static references to x360ce.Engine library or
            // program tries to load x360ce.Engine.dll before AssemblyResolve event is available and fails.
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
            if (IsDebug)
            {
                StartApp(args);
                return;
            }
            try
            {
                StartApp(args);
            }
            catch (Exception ex)
            {
                var message = ExceptionToText(ex);
                var box     = new Controls.MessageBoxForm();
                if (message.Contains("Could not load file or assembly 'Microsoft.DirectX"))
                {
                    message += "===============================================================\r\n";
                    message += "You can click the link below to download Microsoft DirectX.";
                    box.MainLinkLabel.Text    = "http://www.microsoft.com/en-us/download/details.aspx?id=35";
                    box.MainLinkLabel.Visible = true;
                }
                var result = box.ShowForm(message, "Exception!", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                if (result == DialogResult.Cancel)
                {
                    Application.Exit();
                }
            }
        }
예제 #6
0
 static void Main(string[] args)
 {
     try
     {
         //var fi = new FileInfo(Application.ExecutablePath);
         //Directory.SetCurrentDirectory(fi.Directory.FullName);
         // IMPORTANT: Make sure this method don't have any static references to x360ce.Engine library or
         // program tries to load x360ce.Engine.dll before AssemblyResolve event is available and fails.
         AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
         if (!RuntimePolicyHelper.LegacyV2RuntimeEnabledSuccessfully)
         {
             // Failed to enable useLegacyV2RuntimeActivationPolicy at runtime.
         }
         Application.EnableVisualStyles();
         Application.SetCompatibleTextRenderingDefault(false);
         // Requires System.Configuration.Installl reference.
         var ic = new System.Configuration.Install.InstallContext(null, args);
         if (ic.Parameters.ContainsKey("Settings"))
         {
             OpenSettingsFolder(Application.UserAppDataPath);
             OpenSettingsFolder(Application.CommonAppDataPath);
             OpenSettingsFolder(Application.LocalUserAppDataPath);
             return;
         }
         if (!CheckSettings())
         {
             return;
         }
         //Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
         MainForm.Current = new MainForm();
         if (ic.Parameters.ContainsKey("Exit"))
         {
             MainForm.Current.BroadcastMessage(MainForm.wParam_Close);
             return;
         }
         if (!IsOneCopyRunningAlready())
         {
             Application.Run(MainForm.Current);
         }
     }
     catch (Exception ex)
     {
         var message = "";
         AddExceptionMessage(ex, ref message);
         if (ex.InnerException != null)
         {
             AddExceptionMessage(ex.InnerException, ref message);
         }
         var box = new Controls.MessageBoxForm();
         if (message.Contains("Could not load file or assembly 'Microsoft.DirectX"))
         {
             message += "===============================================================\r\n";
             message += "You can click the link below to download Microsoft DirectX.";
             box.MainLinkLabel.Text    = "http://www.microsoft.com/en-us/download/details.aspx?id=35";
             box.MainLinkLabel.Visible = true;
         }
         var result = box.ShowForm(message, "Exception!", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
         if (result == DialogResult.Cancel)
         {
             Application.Exit();
         }
     }
 }
예제 #7
0
파일: Program.cs 프로젝트: jeppeter/x360ce
 static void Main(string[] args)
 {
     try
     {
         AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
         if (!RuntimePolicyHelper.LegacyV2RuntimeEnabledSuccessfully)
         {
             // Failed to enable useLegacyV2RuntimeActivationPolicy at runtime.
         }
         Application.EnableVisualStyles();
         Application.SetCompatibleTextRenderingDefault(false);
         // Requires System.Configuration.Installl reference.
         var ic = new System.Configuration.Install.InstallContext(null, args);
         if (ic.Parameters.ContainsKey("Settings"))
         {
             OpenSettingsFolder(Application.UserAppDataPath);
             OpenSettingsFolder(Application.CommonAppDataPath);
             OpenSettingsFolder(Application.LocalUserAppDataPath);
             return;
         }
         if (!CheckSettings()) return;
         //Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
         MainForm.Current = new MainForm();
         if (ic.Parameters.ContainsKey("Exit"))
         {
             MainForm.Current.BroadcastMessage(MainForm.wParam_Close);
             return;
         }
         var ini = new Ini(SettingManager.IniFileName);
         var oneCopy = !ini.File.Exists || ini.GetValue("Options", SettingName.AllowOnlyOneCopy) == "1";
         if (!(oneCopy && MainForm.Current.BroadcastMessage(MainForm.wParam_Restore)))
         {
             Application.Run(MainForm.Current);
         }
     }
     catch (Exception ex)
     {
         var message = "";
         AddExceptionMessage(ex, ref message);
         if (ex.InnerException != null) AddExceptionMessage(ex.InnerException, ref message);
         var box = new Controls.MessageBoxForm();
         if (message.Contains("Could not load file or assembly 'Microsoft.DirectX"))
         {
             message += "===============================================================\r\n";
             message += "You can click the link below to download Microsoft DirectX.";
             box.MainLinkLabel.Text = "http://www.microsoft.com/en-us/download/details.aspx?id=35";
             box.MainLinkLabel.Visible = true;
         }
         var result = box.ShowForm(message, "Exception!", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
         if (result == DialogResult.Cancel) Application.Exit();
     }
 }