public void Initialize() { String homeFolder = @Path.GetFullPath(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)); m_saveDefaultPath = homeFolder + @"\Roostertail Games\T3DConvoEditor\"; m_dirty = false; m_log = new CLog(); m_log.Filename = m_saveDefaultPath + "T3DConvoEditor.log"; m_personalPath = Path.GetFullPath(Environment.GetFolderPath(Environment.SpecialFolder.Personal)) + @"\Roostertail Games\T3DConvoEditor\";; m_log.WriteLine("Checking for settings file in " + m_personalPath); if (File.Exists(m_personalPath + "T3DConvoEditor.ini")) { m_log.WriteLine("Opening settings from " + m_personalPath); m_settings = new CSettings(m_personalPath + "T3DConvoEditor.ini"); } else { m_log.WriteLine("Opening settings file from application path"); m_settings = new CSettings("T3DConvoEditor.ini"); } m_settings.LoadSettings(); m_preferences = new FPreferences(m_settings); m_preferences.Settings = m_settings; m_nodeEdit = new FNodeEdit(); m_nodeEdit.Text = "Edit Conversation Selection List"; m_nodeEdit.MainForm = this; m_partEdit = new FConvPartEdit(); m_plugins = new FPluginPage(m_log); m_log.WriteLine("T3D Conversation Editor started"); if (!Directory.Exists(m_saveDefaultPath)) { Directory.CreateDirectory(m_saveDefaultPath); } sfdSaveGraphFile.InitialDirectory = m_saveDefaultPath; ofdOpenFile.InitialDirectory = m_saveDefaultPath; String defFileName = m_settings.Attributes["[Default]"]["DEFAULTFILENAME"]; tbxConvoName.Text = defFileName.Remove(defFileName.LastIndexOf('.')); graphCtrl.NodeAdded += new EventHandler <AcceptNodeEventArgs>(onNodeAdded); int width = pnlWork.Width - (2 * pnlWork.Margin.All); int height = pnlWork.Height - (2 * pnlWork.Margin.All); Rectangle graphBounds = new Rectangle(new Point(pnlWork.Margin.All, pnlWork.Margin.All), new Size(width, height)); pnlGraph.Bounds = graphBounds; pnlGraph.Controls.Add(graphCtrl); _Plugins = m_plugins.Plugins; if (_Plugins.ContainsKey("TSWriterPlugin")) { IPlugin plugin = _Plugins["TSWriterPlugin"]; plugin.Initialize(graphCtrl, m_log); m_currentPluginSettings = plugin.Settings; } }
private void btnRestore_Click(object sender, EventArgs e) { ofdOpen.Filter = "BAK files|*.bak"; if (ofdOpen.ShowDialog() == DialogResult.OK) { String target = ofdOpen.FileName.Replace(".bak", ""); File.Copy(ofdOpen.FileName, target, true); m_iniFile.LoadSettings(); } }
private void frmMain_Load(object sender, EventArgs e) { try { if (CSettings.LoadSettings()) { object objOnionAddress = CSettings.GetValue("OnionAddress"); if (objOnionAddress != null) { Program.ControllerConfig.OnionAddress = (String)objOnionAddress; } object objOnionPort = CSettings.GetValue("OnionPort"); if (objOnionPort != null && Int32.TryParse((String)objOnionPort, out Program.ControllerConfig.OnionPort)) { } object objTorIP = CSettings.GetValue("TorIP"); if (objTorIP != null) { Program.ControllerConfig.Tor_Host = (String)objTorIP; } object objTorPort = CSettings.GetValue("TorPort"); if (objTorPort != null && Int32.TryParse((String)objTorPort, out Program.ControllerConfig.Tor_Port)) { } object objAdminUsername = CSettings.GetValue("AdminUsername"); if (objAdminUsername != null) { Program.ControllerConfig.AdminUsername = (string)objAdminUsername; } object objAdminPassword = CSettings.GetValue("AdminPassword"); if (objAdminPassword != null) { Program.ControllerConfig.AdminPassword = (string)objAdminPassword; } } m_Controller = new CController(this); } catch (Exception ex) { MessageBox.Show("There has been a fatal error. The controller wont work. Please contact support."); } }
private void loadINI(String filename) { m_iniFile = new CSettings(filename); m_iniFile.LoadSettings(); tctrlSettings.Controls.Clear(); var list = m_iniFile.Attributes.Keys.ToList(); list.Sort(); foreach (String attrib in list) { Point topleft = new Point(4, 4); if (m_iniFile.Attributes[attrib].Count < 1) { continue; } TabPage page = new TabPage(attrib); page.Name = attrib; tctrlSettings.TabPages.Add(page); Panel panel = new Panel(); panel.Dock = DockStyle.Fill; panel.Name = "pnl" + attrib; page.Controls.Add(panel); ListBox listbox = new ListBox(); listbox.Name = "lbx" + attrib; listbox.Width = 300; listbox.Height = panel.Height - 8; panel.Controls.Add(listbox); listbox.Location = topleft; List <String> boxItems = new List <String>(); foreach (String setting in m_iniFile.Attributes[attrib].Keys) { boxItems.Add(setting); } boxItems.Sort(); foreach (String entry in boxItems) { listbox.Items.Add(entry); } listbox.SelectedIndexChanged += listbox_SelectedIndexChanged; topleft = new Point(listbox.Right + 4, listbox.Top); // examine/edit Label lbl = new Label(); lbl.Name = "lbl" + attrib; lbl.Text = "Field Value:"; lbl.Width = 200; lbl.TextAlign = ContentAlignment.MiddleLeft; panel.Controls.Add(lbl); lbl.Location = topleft; topleft.Y += lbl.Height + 4; TextBox box = new TextBox(); box.Width = 300; box.Name = "tbx" + attrib; panel.Controls.Add(box); box.Location = topleft; Button btn = new Button(); topleft.Y = (box.Top - ((btn.Height - box.Height) / 2)); topleft.X = box.Right + 4; btn.Name = "btn" + attrib; btn.Text = "Set"; btn.Click += button_Click; panel.Controls.Add(btn); btn.Location = topleft; // add Label lblAdd = new Label(); lblAdd.Name = "lblAdd" + attrib; lblAdd.Text = "Add"; lblAdd.Width = 200; lblAdd.TextAlign = ContentAlignment.MiddleLeft; panel.Controls.Add(lblAdd); topleft.X = lbl.Left; topleft.Y = box.Top + box.Height + 4; lblAdd.Location = topleft; topleft.Y += lblAdd.Height + 4; TextBox boxAddName = new TextBox(); boxAddName.Width = 200; boxAddName.Name = "tbxAdd" + attrib + "Name"; panel.Controls.Add(boxAddName); boxAddName.Location = topleft; topleft.X += boxAddName.Width + 4; TextBox boxAddVal = new TextBox(); boxAddVal.Width = 96; boxAddVal.Name = "tbxAdd" + attrib + "Value"; panel.Controls.Add(boxAddVal); boxAddVal.Location = topleft; Button btnAdd = new Button(); topleft.Y = (boxAddName.Top - ((btnAdd.Height - boxAddName.Height) / 2)); topleft.X = boxAddVal.Right + 4; btnAdd.Name = "btnAdd" + attrib; btnAdd.Text = "Add"; btnAdd.Click += button_AddClick; panel.Controls.Add(btnAdd); btnAdd.Location = topleft; m_selectedTabIndex = tctrlSettings.SelectedIndex; } }
static void Main(string[] args) { Console.Title = String.Format("{0} [{1}]", CConstants.ServerName, CConfig.ServerVersion); Console.WriteLine(CConstants.WelcomeMessage); if (!File.Exists("GeoIP.dat")) { Console.WriteLine("[WARNING] GeoIP.dat is not found. Country statistics wont work."); } else { ls = new LookupService("GeoIP.dat", LookupService.GEOIP_MEMORY_CACHE); } try { if (CSettings.LoadSettings()) { object objServerPort = CSettings.GetValue("ServerPort"); if (objServerPort != null) { if (int.TryParse((String)objServerPort, out CConfig.ServerPort)) { Console.WriteLine(CConstants.PortLoaded, CConfig.ServerPort); } } else { Console.WriteLine(CConstants.ErrorReading, "ServerPort"); } object objDatabaseName = CSettings.GetValue("DatabaseName"); if (objDatabaseName != null) { CConfig.DatabaseName = (String)objDatabaseName; Console.WriteLine(CConstants.DatabaseLoaded, CConfig.DatabaseName); } else { Console.WriteLine(CConstants.ErrorReading, "DatabaseName"); } object objSSLPassword = CSettings.GetValue("SSLPassword"); if (objSSLPassword != null) { CConfig.SSLPassword = (String)objSSLPassword; Console.WriteLine(CConstants.SSLPasswordLoaded, CConfig.SSLPassword); } else { Console.WriteLine(CConstants.ErrorReading, "SSLPassword"); } object objCertFilename = CSettings.GetValue("SSLCertFilename"); if (objCertFilename != null) { CConfig.SSLCertificateFilename = (String)objCertFilename; Console.WriteLine(CConstants.SSLCertificateFilenameLoaded, CConfig.SSLCertificateFilename); } else { Console.WriteLine(CConstants.ErrorReading, "SSLCertFilename"); } object objResultsPerPage = CSettings.GetValue("ResultsPerPage"); if (objResultsPerPage != null) { if (Int32.TryParse((String)objResultsPerPage, out CConfig.ResultsPerPage)) { Console.WriteLine(CConstants.ResultsPerPageLoaded, CConfig.ResultsPerPage); } } else { Console.WriteLine(CConstants.ErrorReading, "ResultsPerPage"); } } else { CSettings.SetValue("ServerPort", (object)CConfig.ServerPort); CSettings.SetValue("DatabaseName", (object)CConfig.DatabaseName); CSettings.SetValue("SSLPassword", (object)CConfig.SSLPassword); CSettings.SetValue("ResultsPerPage", (object)CConfig.ResultsPerPage); CSettings.SetValue("SSLCertFilename", (object)CConfig.SSLCertificateFilename); if (CSettings.SaveSettings()) { Console.WriteLine(CConstants.SettingsCreated); Console.ReadKey(); return; } } DatabaseClient = new CDatabase(CConfig.DatabaseName); GopnikServer = new CGopnikServer(CConfig.ServerPort); if (GopnikServer.StartServer()) { Console.WriteLine(CConstants.ServerStartedMessage); } } catch (System.Exception ex) { Console.WriteLine(ex.ToString()); Console.ReadLine(); } String strInput = String.Empty; while ((strInput = Console.ReadLine()) != string.Empty) { String[] arr_strData = strInput.Split(' '); switch (arr_strData[0]) { case ".help": Console.WriteLine("[HELP] .addmaster username password - Adds a new Master to the Database."); Console.WriteLine("[HELP] .delmaster ID - Removes a Master by its ID from database."); Console.WriteLine("[HELP] .masters - Shows all current available Masters."); break; case ".addmaster": if (arr_strData.Length != 3) { Console.WriteLine("[ERROR] Invalid arguments for command. Example: .addmaster username password"); break; } if (DatabaseClient.ExecuteNonResultQuery(String.Format("INSERT INTO masters(master_username, master_password) VALUES('{0}', '{1}')", arr_strData[1], arr_strData[2]))) { Console.WriteLine("[EVENT] New master added to database."); } break; case ".delmaster": if (arr_strData.Length != 2) { Console.WriteLine("[ERROR] Invalid arguments for command. Example: .delmaster id"); break; } Int32 iMasterID = -1; if (!Int32.TryParse(arr_strData[1], out iMasterID)) { Console.WriteLine("[ERROR] Argument expects Integer value."); break; } if (DatabaseClient.ExecuteNonResultQuery(String.Format("DELETE FROM masters WHERE master_id={0}", iMasterID))) { Console.WriteLine("[EVENT] Master removed from database."); } break; case ".masters": SQLiteDataReader Result = DatabaseClient.ExecuteReadQuery("SELECT * FROM masters"); if (Result.HasRows) { while (Result.Read()) { Console.WriteLine("ID: {0} | Username: {1} | Password: {2}", Result["master_id"], Result["master_username"], Result["master_password"]); } } else { Console.WriteLine("No masters found in database."); } break; case ".exit": break; default: break; } } }