Esempio n. 1
0
        public static void Main(string[] sargs)
        {
            Thread.CurrentThread.CurrentUICulture = Culture;
            CommandArgs args = new CommandArgs (sargs);

            if (args.styles) Application.EnableVisualStyles ();

            // Damn .NET text rendering
            Application.SetCompatibleTextRenderingDefault(false);

            Directory.SetCurrentDirectory (System.IO.Path.GetDirectoryName (Application.ExecutablePath));

            Localizations = new LocalizationInterface ();
            try {
                string [] langfiles = Directory.GetFiles ("MGE3", "*.lng");
                foreach (string langfile in langfiles) {
                    Localizations.Add (langfile);
                }
            } catch { };
            string language = "English (default)";
            bool autoLanguage = true;
            try {
                INIFile MGEini = new INIFile (iniFileName, new INIFile.INIVariableDef [] { INIFile.iniDefEmpty, MainForm.iniLanguage, MainForm.iniAutoLang });
                language = MGEini.getKeyString ("Language");
                autoLanguage = (MGEini.getKeyValue ("AutoLang") == 1);
            } catch { }
            Localizations.Current = language;
            Localizations.ApplyStrings("", strings);

            if (args.mutex && !MutexCheck.PerformCheck ()) {
                MessageBox.Show (strings ["MGEguiRunning"], strings ["Error"]);
                return;
            }
            Process [] morrowind = Process.GetProcessesByName ("Morrowind");
            foreach (Process p in morrowind) {
                MessageBox.Show (strings ["MWRunning"], strings ["Error"]);
                return;
            }

            if (!File.Exists ("./morrowind.exe") || !File.Exists ("./morrowind.ini") || !Directory.Exists ("data files")) {
                MessageBox.Show (strings ["NotMWDir"], strings ["Error"]);
                return;
            }
            if (!Directory.Exists ("MGE3") || !File.Exists ("./MGE3/MGEfuncs.dll") || !File.Exists ("./d3d8.dll") ||
               !File.Exists ("./dinput8.dll")) {
                MessageBox.Show (strings ["MGEMissing"], strings ["Error"]);
                return;
            }
            //Morrowind version info
            try {
                FileVersionInfo MorrowVersion = FileVersionInfo.GetVersionInfo ("Morrowind.exe");
                if (MorrowVersion.FileMajorPart != 1 || MorrowVersion.FileMinorPart < 6) {
                    MessageBox.Show (strings ["MWIncompat"], strings ["Error"]);
                    return;
                }
            } catch {
                MessageBox.Show (strings ["MWCorrupt"], strings ["Error"]);
                return;
            }

            runDir = System.Windows.Forms.Application.StartupPath;
            //check if MW registry keys exist
            if (Registry.LocalMachine.OpenSubKey (reg_mw) == null) {
                MessageBox.Show (strings ["MWRegistry"], strings ["Error"]);
                return;
            }

            //Create some structures
            for (int i = 0; i < MACROS; i++) {
                Macros [i] = new Macro ();
            }
            for (int i = 0; i < TRIGGERS; i++) {
                Triggers [i] = new Trigger ();
            }
            DXMain.GetDeviceCaps ();
            mf = new MainForm (autoLanguage);
            Application.Run (mf);
        }
Esempio n. 2
0
        public static void Main(string[] sargs)
        {
            Thread.CurrentThread.CurrentUICulture = Culture;
            CommandArgs args = new CommandArgs (sargs);

            if (args.styles) Application.EnableVisualStyles ();

            // Damn .NET text rendering
            Application.SetCompatibleTextRenderingDefault(false);

            Directory.SetCurrentDirectory (System.IO.Path.GetDirectoryName (Application.ExecutablePath));

            Localizations = new LocalizationInterface ();
            try {
                string [] langfiles = Directory.GetFiles ("MGE3", "*.lng");
                foreach (string langfile in langfiles) {
                    Localizations.Add (langfile);
                }
            } catch { };
            Localizations.Add(new LocalizationInterface.Localization((Form)null));    // Adds truncated variant of default localization.
            String language = DefaultLocalization.Language;
            bool autoLanguage = true;
            try {
                INIFile MGEini = new INIFile (iniFileName, new INIFile.INIVariableDef [] { INIFile.iniDefEmpty, MainForm.iniLanguage, MainForm.iniAutoLang });
                language = MGEini.getKeyString ("Language");
                autoLanguage = (MGEini.getKeyValue ("AutoLang") == 1);
            } catch { }
            Localizations.Current = language;
            Localizations.ApplyStrings("", strings);

            if (args.mutex && !MutexCheck.PerformCheck ()) {
                MessageBox.Show (strings ["MGEguiRunning"], strings ["Error"]);
                return;
            }
            Process [] morrowind = Process.GetProcessesByName ("Morrowind");
            foreach (Process p in morrowind) {
                MessageBox.Show (strings ["MWRunning"], strings ["Error"]);
                return;
            }

            if (!File.Exists ("./morrowind.exe") || !File.Exists ("./morrowind.ini") || !Directory.Exists ("data files")) {
                MessageBox.Show (strings ["NotMWDir"], strings ["Error"]);
                return;
            }
            if (!Directory.Exists ("MGE3") || !File.Exists ("./MGE3/MGEfuncs.dll") || !File.Exists ("./d3d8.dll") ||
               !File.Exists ("./dinput8.dll")) {
                MessageBox.Show (strings ["MGEMissing"], strings ["Error"]);
                return;
            }
            //Morrowind version info
            try {
                FileVersionInfo MorrowVersion = FileVersionInfo.GetVersionInfo ("Morrowind.exe");
                if (MorrowVersion.ProductPrivatePart != 722 && MorrowVersion.ProductPrivatePart != 1029 && MorrowVersion.ProductPrivatePart != 1875 && MorrowVersion.ProductPrivatePart != 1820)
                {
                    MessageBox.Show (strings ["MWIncompat"], strings ["Error"]);
                    return;
                }
            } catch {
                MessageBox.Show (strings ["MWCorrupt"], strings ["Error"]);
                return;
            }
            //Check for dsound.dll
            if (File.Exists ("dsound.dll") && new System.IO.FileInfo ("dsound.dll").Length == 16384) {
                try {
                    File.Delete ("dsound.dll");
                } catch {
                    MessageBox.Show (strings ["DSound"], strings ["Error"]);
                    return;
                }
            }

            runDir = System.Windows.Forms.Application.StartupPath;
            //check if MW registry keys exist
            RegistryKey key = Statics.reg_key_bethesda.OpenSubKey(Statics.reg_morrowind);
            if (key != null) { key.Close(); key = null;
            } else {
                MessageBox.Show (strings ["MWRegistry"], strings ["Error"]);
                return;
            }

            //mendres: Check if MGE needs administrator privileges.
            try {
                key = Statics.reg_key_bethesda.OpenSubKey(Statics.reg_morrowind, true);
            } catch (System.Security.SecurityException) {
                MessageBox.Show(strings["MgeAccess"], strings["Error"]);
                return;
            }
            if (key != null) { key.Close(); key = null; }

            //Create the data files directories MGE uses
            if (!Directory.Exists (@"data files\shaders")) {
                Directory.CreateDirectory (@"data files\shaders");
            }
            if (!Directory.Exists (@"data files\MGE meshes")) {
                Directory.CreateDirectory (@"data files\MGE meshes");
            }
            if (!Directory.Exists (@"data files\Textures\MGE")) {
                Directory.CreateDirectory (@"data files\Textures\MGE");
            }
            if (!Directory.Exists (@"data files\MGE videos")) {
                Directory.CreateDirectory (@"data files\MGE videos");
            }
            if (!Directory.Exists (@"data files\shaders\default")) {
                Directory.CreateDirectory (@"data files\shaders\default");
            }
            if (!Directory.Exists (@"data files\shaders\water")) {
                Directory.CreateDirectory (@"data files\shaders\water");
            }
            //Create some structures
            for (int i = 0; i < MACROS; i++) {
                Macros [i] = new Macro ();
            }
            for (int i = 0; i < TRIGGERS; i++) {
                Triggers [i] = new Trigger ();
            }
            DXMain.GetDeviceCaps ();
            bool GUIchecker = !lightversion;
            while (GUIchecker != lightversion) {
                GUIchecker = lightversion;
                if (lightversion) {
                    mfl = new MainFormLight(autoLanguage);
                    Application.Run(mfl);
                } else {
                    mf = new MainForm (autoLanguage);
                    Application.Run (mf);
                }
            }
        }