Ejemplo n.º 1
0
        private bool LockHome()
        {
            var home = ConfigEditor.GetHome();

            try
            {
                var lockFile = System.IO.Path.Combine(home, "ConfigEditor.lock");
                System.IO.File.Create(lockFile, 1024, System.IO.FileOptions.DeleteOnClose);
                return(true);
            }
            catch (Exception)
            {
                //MessageBox.Show($"Home 已经在编辑中。");
                var processes = Process.GetProcessesByName("ConfigEditor");
                foreach (var process in processes)
                {
                    if (process.MainWindowTitle.Equals(home))
                    {
                        ShowWindowAsync(process.MainWindowHandle, SW_SHOWNOMAL);
                        SetForegroundWindow(process.MainWindowHandle);
                        SwitchToThisWindow(process.MainWindowHandle, true);
                        break;
                    }
                }
                return(false);
            }
        }
Ejemplo n.º 2
0
        private void SaveConfig()
        {
            var options = new JsonSerializerOptions {
                WriteIndented = true
            };

            System.IO.File.WriteAllBytes(GetConfigFileFullName(), JsonSerializer.SerializeToUtf8Bytes(ConfigEditor, options));
            System.IO.File.WriteAllBytes(System.IO.Path.Combine(ConfigEditor.GetHome(), "ProjectConfig.json"),
                                         JsonSerializer.SerializeToUtf8Bytes(ConfigProject, options));
        }
Ejemplo n.º 3
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            // remove deleted directory.
            for (int i = ConfigEditor.RecentHomes.Count - 1; i >= 0; --i)
            {
                string home = ConfigEditor.RecentHomes[i];
                if (System.IO.Directory.Exists(home))
                {
                    continue;
                }
                ConfigEditor.RecentHomes.RemoveAt(i);
            }

            FormSelectRecentHome select = new FormSelectRecentHome();

            select.InitComboRecentHomes(ConfigEditor);
            if (DialogResult.OK != select.ShowDialog(this))
            {
                select.Dispose();
                LoadCancel = true;
                Close();
                return;
            }
            ConfigEditor.SetRecentHome(select.ComboBoxRecentHomes.Text);
            this.Text = select.ComboBoxRecentHomes.Text;
            select.Dispose();
            Environment.CurrentDirectory = ConfigEditor.GetHome();
            if (false == LockHome())
            {
                LoadCancel = true;
                Close();
                return;
            }
            LoadConfigProject();

            Documents = new Documents();
            Documents.Build();

            if (ConfigEditor.FormMainLocation != null)
            {
                this.Location = ConfigEditor.FormMainLocation;
            }
            if (ConfigEditor.FormMainSize != null)
            {
                this.Size = ConfigEditor.FormMainSize;
            }
            this.WindowState = ConfigEditor.FormMainState;

            this.TopMost = true;
            this.BringToFront();
            this.TopMost = false;
        }
Ejemplo n.º 4
0
 private void LoadConfigProject()
 {
     try
     {
         string json = Encoding.UTF8.GetString(System.IO.File.ReadAllBytes(
                                                   System.IO.Path.Combine(ConfigEditor.GetHome(), "ProjectConfig.json")));
         ConfigProject = JsonSerializer.Deserialize <ProjectConfig>(json);
     }
     catch (Exception)
     {
         //MessageBox.Show(ex.ToString());
     }
     if (null == ConfigProject)
     {
         ConfigProject = new ProjectConfig();
     }
 }
Ejemplo n.º 5
0
        public static void getConfigData()
        {
            string DataPath = Path.GetFullPath(Directory.GetCurrentDirectory()) + "\\data\\";
            string FilePath = DataPath + "Config.dat";
            string EncryptKey = Properties.Settings.Default.GUID;

            if (!Directory.Exists(DataPath))
            {
                Directory.CreateDirectory(DataPath);
            }

            if (File.Exists(FilePath))
            {
                ConfigEncryptor ConfigEncrypt = new ConfigEncryptor();
                EncryptKey = Properties.Settings.Default.GUID;

                try
                {
                    ConfigEncrypt.DecryptConfig(FilePath, DataPath, EncryptKey);
                }
                catch
                {
                    MessageBox.Show("Config has become corrupt. Loading default values. Please update values again.");
                    corruptConfig = true;
                }

                if (corruptConfig)
                    goto Advance;

                StreamReader reader = new StreamReader(FilePath);
                ConfigEditor.ConfigEditor config = new ConfigEditor.ConfigEditor(reader);
                reader.Close();

                ConfigEncrypt.EncryptConfig(FilePath, DataPath, EncryptKey);

                ConfigProperties.timerInterval = (string)config.GetValue("TimerInterval");

                if ((string)config.GetValue("MangosHosted") == "1")
                {
                    ConfigProperties.mangosHosted = true;
                }
                else
                {
                    ConfigProperties.mangosHosted = false;
                }

                if ((string)config.GetValue("RealmHosted") == "1")
                {
                    ConfigProperties.realmHosted = true;
                }
                else
                {
                    ConfigProperties.realmHosted = false;
                }

                ConfigProperties.mangosAppName = (string)config.GetValue("MangosAppName");
                ConfigProperties.mangosAppPath = (string)config.GetValue("MangosAppPath");
                ConfigProperties.realmAppName = (string)config.GetValue("RealmAppName");
                ConfigProperties.realmAppPath = (string)config.GetValue("RealmAppPath");
                ConfigProperties.dbHost = (string)config.GetValue("DbHost");
                ConfigProperties.dbPort = (string)config.GetValue("DbPort");
                ConfigProperties.dbUser = (string)config.GetValue("DbUser");
                ConfigProperties.dbPassword = (string)config.GetValue("DbPassword");
                ConfigProperties.mangosDatabaseName = (string)config.GetValue("MangosDatabaseName");
                ConfigProperties.realmDatabaseName = (string)config.GetValue("RealmDatabaseName");
                ConfigProperties.charDatabaseName = (string)config.GetValue("CharDatabaseName");
                ConfigProperties.mangosMOTD = (string)config.GetValue("MangosMOTD");
                goto Finish;

            Advance:
                ConfigProperties.timerInterval = "10000";
                ConfigProperties.mangosHosted = true;
                ConfigProperties.realmHosted = true;
                ConfigProperties.mangosAppName = "mangosd";
                ConfigProperties.mangosAppPath = "C:\\mangos\\";
                ConfigProperties.realmAppName = "realmd";
                ConfigProperties.realmAppPath = "C:\\mangos\\";
                ConfigProperties.dbHost = "localhost";
                ConfigProperties.dbPort = "3306";
                ConfigProperties.dbUser = "******";
                ConfigProperties.dbPassword = "******";
                ConfigProperties.mangosDatabaseName = "mangos";
                ConfigProperties.realmDatabaseName = "realm";
                ConfigProperties.charDatabaseName = "characters";
                ConfigProperties.mangosMOTD = "Welcome to MaNGOS";
                editConfig showEditConfig = new editConfig();
                showEditConfig.Show();

            Finish: ;
            }
            else
            {
                ConfigProperties.timerInterval = "10000";
                ConfigProperties.mangosHosted = true;
                ConfigProperties.realmHosted = true;
                ConfigProperties.mangosAppName = "mangosd";
                ConfigProperties.mangosAppPath = "C:\\mangos\\";
                ConfigProperties.realmAppName = "realmd";
                ConfigProperties.realmAppPath = "C:\\mangos\\";
                ConfigProperties.dbHost = "localhost";
                ConfigProperties.dbPort = "3306";
                ConfigProperties.dbUser = "******";
                ConfigProperties.dbPassword = "******";
                ConfigProperties.mangosDatabaseName = "mangos";
                ConfigProperties.realmDatabaseName = "realm";
                ConfigProperties.charDatabaseName = "characters";
                ConfigProperties.mangosMOTD = "Welcome to MaNGOS";

                MessageBox.Show(string.Format(Resources.hcStringResources.Global_DataAccess_Config_NotSavedAnyConfigValues ));
                editConfig showEditConfig = new editConfig();
                showEditConfig.Show();
            }
        }
Ejemplo n.º 6
0
        public static void setConfigData(string timerInterval,
                                         bool mangosHosted,
                                         bool realmHosted,
                                         string mangosAppName,
                                         string realmAppName,
                                         string mangosAppPath,
                                         string realmAppPath,
                                         string dbHost,
                                         string dbPort,
                                         string dbUser,
                                         string dbPassword,
                                         string mangosDbName,
                                         string realmDbName,
                                         string charDbName,
                                         string mangosMOTD,
                                         bool firstUse)
        {
            string DataPath = Path.GetFullPath(Directory.GetCurrentDirectory()) + "\\data\\";
            string FilePath = DataPath + "Config.dat";
            string EncryptKey = Properties.Settings.Default.GUID;

            if (corruptConfig)
            {
                File.Delete(FilePath);
                File.Delete(DataPath + "Temp.dat");
                corruptConfig = false;
            }

            if (File.Exists(FilePath))
            {
                ConfigEncryptor ConfigEncrypt = new ConfigEncryptor();
                EncryptKey = Properties.Settings.Default.GUID;

                ConfigEncrypt.DecryptConfig(FilePath, DataPath, EncryptKey);

                StreamReader reader = new StreamReader(FilePath);
                ConfigEditor.ConfigEditor config = new ConfigEditor.ConfigEditor(reader);
                reader.Close();
                StreamWriter writer = new StreamWriter(FilePath);

                config.SetValue("TimerInterval", timerInterval);

                if (mangosHosted)
                {
                    config.SetValue("MangosHosted", "1");
                }
                else
                {
                    config.SetValue("MangosHosted", "0");
                }

                if (realmHosted)
                {
                    config.SetValue("RealmHosted", "1");
                }
                else
                {
                    config.SetValue("RealmHosted", "0");
                }

                config.SetValue("MangosAppName", mangosAppName);
                config.SetValue("RealmAppName", realmAppName);
                config.SetValue("MangosAppPath", mangosAppPath);
                config.SetValue("RealmAppPath", realmAppPath);
                config.SetValue("DbHost", dbHost);
                config.SetValue("DbPort", dbPort);
                config.SetValue("DbUser", dbUser);
                config.SetValue("DbPassword", dbPassword);
                config.SetValue("MangosDatabaseName", mangosDbName);
                config.SetValue("RealmDatabaseName", realmDbName);
                config.SetValue("CharDatabaseName", charDbName);
                config.SetValue("MangosMOTD", mangosMOTD);

                config.SaveConfig(writer);
                writer.Close();

                ConfigEncrypt.EncryptConfig(FilePath, DataPath, EncryptKey);
            }
            else
            {
                ConfigEncryptor ConfigEncrypt = new ConfigEncryptor();
                EncryptKey = Properties.Settings.Default.GUID;

                ConfigEditor.ConfigEditor config = new ConfigEditor.ConfigEditor();
                StreamWriter writer = new StreamWriter(FilePath);

                config.SetValue("TimerInterval", timerInterval);

                if (mangosHosted)
                {
                    config.SetValue("MangosHosted", "1");
                }
                else
                {
                    config.SetValue("MangosHosted", "0");
                }

                if (realmHosted)
                {
                    config.SetValue("RealmHosted", "1");
                }
                else
                {
                    config.SetValue("RealmHosted", "0");
                }

                config.SetValue("MangosAppName", mangosAppName);
                config.SetValue("RealmAppName", realmAppName);
                config.SetValue("MangosAppPath", mangosAppPath);
                config.SetValue("RealmAppPath", realmAppPath);
                config.SetValue("DbHost", dbHost);
                config.SetValue("DbPort", dbPort);
                config.SetValue("DbUser", dbUser);
                config.SetValue("DbPassword", dbPassword);
                config.SetValue("MangosDatabaseName", mangosDbName);
                config.SetValue("RealmDatabaseName", realmDbName);
                config.SetValue("CharDatabaseName", charDbName);
                config.SetValue("MangosMOTD", mangosMOTD);

                config.SaveConfig(writer);
                writer.Close();

                ConfigEncrypt.EncryptConfig(FilePath, DataPath, EncryptKey);
            }

            getConfigData();
        }
Ejemplo n.º 7
0
        private void buildButton_Click(object sender, EventArgs e)
        {
            while (true)
            {
                if (string.IsNullOrEmpty(ConfigProject.ServerSrcDirectory) ||
                    string.IsNullOrEmpty(ConfigProject.ClientSrcDirectory) ||
                    string.IsNullOrEmpty(ConfigProject.DataOutputDirectory)
                    )
                {
                    if (DialogResult.Cancel == MessageBox.Show("Build输出目录没有配置。请先设置。",
                                                               "配置错误", MessageBoxButtons.OKCancel))
                    {
                        return;
                    }
                    OpenFormProjectConfig();
                    continue; // check again.
                }
                if (System.IO.Path.GetFullPath(ConfigProject.DataOutputDirectory).StartsWith(ConfigEditor.GetHome()))
                {
                    MessageBox.Show("数据输出目录不能是配置Home的子目录。");
                    OpenFormProjectConfig();
                    continue;
                }
                break;
            }
            FormBuildProgress progress = new FormBuildProgress();

            progress.ShowDialog();
            progress.StopAndWait();
            progress.Dispose();
        }