private void DoImage(HttpProcessor oHttpProcessor) { if (DoCacheResponseIfWarranted(oHttpProcessor)) { return; } LoadBinary(oHttpProcessor); string sImagePath = htCachedBinaryPaths[oHttpProcessor.pathParts[1].ToLower()]?.ToString(); if (string.IsNullOrWhiteSpace(sImagePath) || !File.Exists(sImagePath)) { htCachedImageHTML[oHttpProcessor.pathParts[1]] = Properties.Resources.HTML_NoResource .Replace("<!-- SecondsBetweenRefresh -->", (PluginAppSettings.GetInt("SecondsBetweenRefresh")).ToString()) .Replace("<!-- Path -->", sImagePath) .Replace("<!-- Title -->", PluginHelper.StateManager.GetAllSelectedGames()[0].Title) ; htCachedImagePaths[oHttpProcessor.pathParts[1]] = ""; } else if (htCachedImagePaths[oHttpProcessor.pathParts[1].ToLower()]?.ToString() != sImagePath) { htCachedImagePaths[oHttpProcessor.pathParts[1]] = sImagePath; htCachedImageHTML[oHttpProcessor.pathParts[1]] = Properties.Resources.HTML_Marque .Replace("<!-- SecondsBetweenRefresh -->", PluginAppSettings.GetString("SecondsBetweenRefresh")) .Replace("<!-- Base64Image -->", MakeBinarySrcData(sImagePath, (byte[])htCachedBinaries[oHttpProcessor.pathParts[1]])); } WriteImageHTML(oHttpProcessor, htCachedImageHTML[oHttpProcessor.pathParts[1]]?.ToString()); }
public void StartHttpServices() { MarquesasHttpServerInstance.RunningServer.port = PluginAppSettings.GetBoolean("PortEnabled") ? PluginAppSettings.GetInt("Port") : -1; MarquesasHttpServerInstance.RunningServer.secure_port = PluginAppSettings.GetBoolean("SecurePortEnabled") ? PluginAppSettings.GetInt("SecurePort") : -1; MarquesasHttpServerInstance.RunningServer.Initialize(); MarquesasHttpServerInstance.RunningServer.WarnIfPortsAreNotAvailable(); MarquesasHttpServerInstance.RunningServer.Start(); MarquesasHttpServerInstance.RunningServer.FirstTimeRunCheck(); }
private void StoreSettingsInAppStrings() { PluginAppSettings.SetString("Port", txtPort.Text); PluginAppSettings.SetString("PortEnabled", chkPortEnabled.Checked ? "True" : "False"); PluginAppSettings.SetString("SecurePort", txtSecurePort.Text); PluginAppSettings.SetString("SecurePortEnabled", chkSecurePortEnabled.Checked ? "True" : "False"); PluginAppSettings.SetString("SecondsBetweenRefresh", nudSecondsBetweenRefresh.Value.ToString()); PluginAppSettings.SetString("AutomaticUpdates", cmbAutomaticUpdates.SelectedItem.ToString() == "On" ? "True" : "False"); }
private static void SelectedGameMethods(HttpProcessor oHttpProcessor) { string sJSONResponse = string.Empty; string sMethodName = oHttpProcessor.pathParts[1].ToLower(); if (!PluginAppSettings.GetBoolean("WriteEnabled") && !sMethodName.ToLower().StartsWith("get")) { oHttpProcessor.writeFailure("Marquesas Server in Read Only Mode."); return; } string[] oBooleans = { "true", "false", "1", "0", "yes", "no" }; string sParamater = string.Empty; if (oHttpProcessor.pathParts.Length > 2) { sParamater = oHttpProcessor.pathParts[2].ToLower(); } MethodInfo[] oGameMethods = typeof(IGame).GetMethods(); foreach (MethodInfo oMethod in oGameMethods) { if (oMethod.Name.ToLower() == sMethodName) { if (sParamater == String.Empty && oMethod.GetParameters().Length == 0) { sJSONResponse = JsonSerializer.Serialize(oMethod.Invoke(PluginHelper.StateManager.GetAllSelectedGames()[0], new object[] { })); break; } else if (sParamater != String.Empty && oMethod.GetParameters().Length > 0) { if (oMethod.GetParameters()[0].ParameterType.ToString() == "System.Boolean") { if (Boolean.TryParse(sParamater, out bool bParamater) && oBooleans.Contains(sParamater.ToLower())) { sJSONResponse = JsonSerializer.Serialize(oMethod.Invoke(PluginHelper.StateManager.GetAllSelectedGames()[0], new object[] { bParamater })); break; } else { continue; } } else { sJSONResponse = JsonSerializer.Serialize(oMethod.Invoke(PluginHelper.StateManager.GetAllSelectedGames()[0], new object[] { sParamater })); break; } } } } WriteJSON(oHttpProcessor, sJSONResponse); }
//public void StartSuperSockets() //{ // //Setup the appServer // if (!SuperSocketAppServerInstance.RunningServer.Setup(PluginAppSettings.GetInt("SuperSocketPort"))) //Setup with listening port // { // // Failed to setup! // MessageBox.Show("Failed setup for Socket Server.", Resources.ApplicationName, MessageBoxButtons.OK); // return; // } // //Try to start the appServer // if (!SuperSocketAppServerInstance.RunningServer.Start()) // { // // Failed to start! // MessageBox.Show("Failed to start Socket Server on port " + PluginAppSettings.GetInt("SuperSocketPort") + ".", Resources.ApplicationName, MessageBoxButtons.OK); // return; // } //} private void btnSave_Click(object sender, EventArgs e) { if (ValidateSettings()) { StoreSettingsInAppStrings(); PluginAppSettings.Save(); btnSave.Enabled = false; btnCheckForUpdates.Enabled = true; } }
private void SetHelpText() { toolTip1.SetToolTip(txtPort, AddNewLinesForTooltip(PluginAppSettings.GetString("Port_Help").Replace(" ", " "))); toolTip1.SetToolTip(chkPortEnabled, AddNewLinesForTooltip(PluginAppSettings.GetString("PortEnabled_Help").Replace(" ", " "))); toolTip1.SetToolTip(txtSecurePort, AddNewLinesForTooltip(PluginAppSettings.GetString("SecurePort_Help").Replace(" ", " "))); toolTip1.SetToolTip(chkSecurePortEnabled, AddNewLinesForTooltip(PluginAppSettings.GetString("SecurePortEnabled_Help").Replace(" ", " "))); toolTip1.SetToolTip(nudSecondsBetweenRefresh, AddNewLinesForTooltip(PluginAppSettings.GetString("SecondsBetweenRefresh_Help").Replace(" ", " "))); toolTip1.SetToolTip(cmbAutomaticUpdates, AddNewLinesForTooltip(PluginAppSettings.GetString("AutomaticUpdates_Help").Replace(" ", " "))); toolTip1.SetToolTip(lblLaunchPort, AddNewLinesForTooltip("Browse index.")); toolTip1.SetToolTip(lblLaunchSecurePort, AddNewLinesForTooltip("Browse index.")); }
private static bool OneAndOnlyOneGameSelected(HttpProcessor oHttpProcessor) { if (PluginHelper.StateManager.GetAllSelectedGames()?.Length == 1) { return(true); } else { WriteImageHTML(oHttpProcessor, Properties.Resources.HTML_NoGame.Replace("<!-- SecondsBetweenRefresh -->", (PluginAppSettings.GetInt("SecondsBetweenRefresh")).ToString())); return(false); } }
new public void Initialize() { if (!int.TryParse(PluginAppSettings.GetString("GetAllGamesLimit"), out giGetAllGamesLimit)) { giGetAllGamesLimit = 50; } gsAccessControlAllowOrigin = PluginAppSettings.GetString("Access-Control-Allow-Origin"); if (string.IsNullOrEmpty(gsAccessControlAllowOrigin)) { gsAccessControlAllowOrigin = "*"; } base.Initialize(); }
private void frmSettings_Load(object sender, EventArgs e) { txtPort.Text = PluginAppSettings.GetInt("Port") == 0 ? "80" : PluginAppSettings.GetInt("Port").ToString(); txtSecurePort.Text = PluginAppSettings.GetInt("SecurePort") == 0 ? "443" : PluginAppSettings.GetInt("SecurePort").ToString(); chkPortEnabled.Checked = PluginAppSettings.GetBoolean("PortEnabled"); chkSecurePortEnabled.Checked = PluginAppSettings.GetBoolean("SecurePortEnabled"); nudSecondsBetweenRefresh.Value = (PluginAppSettings.GetInt("SecondsBetweenRefresh") > 0 && PluginAppSettings.GetInt("SecondsBetweenRefresh") < 1000) ? PluginAppSettings.GetInt("SecondsBetweenRefresh") : 15; cmbAutomaticUpdates.SelectedIndex = cmbAutomaticUpdates.FindString(PluginAppSettings.GetBoolean("AutomaticUpdates") ? "On" : "Off"); SetServerStatus(); btnSave.Enabled = false; btnCheckForUpdates.Enabled = true; }
public void FirstTimeRunCheck() { if ((IsRunning.Item1 || port == -1) && (IsRunning.Item2 || secure_port == -1) && !PluginAppSettings.GetBoolean("NotFirstTimeRun")) { PluginAppSettings.SetString("NotFirstTimeRun", "True"); PluginAppSettings.Save(); if (IsRunning.Item1 || IsRunning.Item2) { if (MessageBox.Show(Resources.FirstTimeRun, Resources.ApplicationName + " First Time Run", MessageBoxButtons.OKCancel) == DialogResult.OK) { LaunchIndexPage(); } } } }
private static bool DoCacheResponseIfWarranted(HttpProcessor oHttpProcessor) { if (PluginAppSettings.GetBoolean("CacheDisabled")) { return(false); } // Cache the response in the browser using the Etag and If-None-Match if (oHttpProcessor.pathParts != null && oHttpProcessor.httpHeaders.ContainsKey("if-none-match") && PluginHelper.StateManager.GetAllSelectedGames()?.Length == 1 && oHttpProcessor.httpHeaders["if-none-match"] == oHttpProcessor.request_url + gsEtagSeperator + PluginHelper.StateManager.GetAllSelectedGames()[0].Id) { oHttpProcessor.writeNotModified(); return(true); } return(false); }
private void DoManual(HttpProcessor oHttpProcessor) { if (DoCacheResponseIfWarranted(oHttpProcessor) || !OneAndOnlyOneGameSelected(oHttpProcessor)) { return; } LoadBinary(oHttpProcessor); string sManualPath = htCachedBinaryPaths["manual"]?.ToString(); if (!string.IsNullOrWhiteSpace(sManualPath) && (htCachedImagePaths["manual"]?.ToString() != sManualPath) && File.Exists(sManualPath)) { htCachedImagePaths["manual"] = sManualPath; htCachedImageHTML["manual"] = Properties.Resources.HTML_Manual .Replace("<!-- SecondsBetweenRefresh -->", (PluginAppSettings.GetInt("SecondsBetweenRefresh") * 1000).ToString()) .Replace("<!-- BinaryPath -->", "/binary/manual") ; } else { htCachedImageHTML["manual"] = Properties.Resources.HTML_NoResource .Replace("<!-- SecondsBetweenRefresh -->", (PluginAppSettings.GetInt("SecondsBetweenRefresh")).ToString()) .Replace("<!-- Path -->", sManualPath) .Replace("<!-- Title -->", PluginHelper.StateManager.GetAllSelectedGames()[0].Title) ; htCachedImagePaths["manual"] = ""; } WriteImageHTML(oHttpProcessor, htCachedImageHTML["manual"].ToString()); }
private void btnClose_Click(object sender, EventArgs e) { if (btnSave.Enabled) { var oMessageBoxResults = MessageBox.Show("You have unsaved changes. Do you wish to save your changes?", "Save Changes?", MessageBoxButtons.YesNoCancel); if (oMessageBoxResults == DialogResult.Cancel) { return; } if (oMessageBoxResults == DialogResult.Yes) { btnSave_Click(sender, e); } else { PluginAppSettings.ReloadConfiguration(); } } this.Close(); }
private void frmSettings_Load(object sender, EventArgs e) { txtPort.Text = PluginAppSettings.GetInt("Port") == 0 ? "80" : PluginAppSettings.GetInt("Port").ToString(); txtSecurePort.Text = PluginAppSettings.GetInt("SecurePort") == 0 ? "443" : PluginAppSettings.GetInt("SecurePort").ToString(); chkPortEnabled.Checked = PluginAppSettings.GetBoolean("PortEnabled"); chkSecurePortEnabled.Checked = PluginAppSettings.GetBoolean("SecurePortEnabled"); nudSecondsBetweenRefresh.Value = (PluginAppSettings.GetInt("SecondsBetweenRefresh") > 0 && PluginAppSettings.GetInt("SecondsBetweenRefresh") < 1000) ? PluginAppSettings.GetInt("SecondsBetweenRefresh") : 15; cmbAutomaticUpdates.SelectedIndex = cmbAutomaticUpdates.FindString(PluginAppSettings.GetBoolean("AutomaticUpdates") ? "On" : "Off"); chkWriteEnabled.Checked = PluginAppSettings.GetBoolean("WriteEnabled"); SetServerStatus(); btnSave.Enabled = false; btnCheckForUpdates.Enabled = true; lblVersion.Text = PluginAppSettings.GetString("Version"); // The version information in the config file overrides the assembly version. if (string.IsNullOrEmpty(lblVersion.Text)) { lblVersion.Text = Assembly.GetExecutingAssembly().GetName().Version.ToString(); } }
private void btnCheckForUpdates_Click(object sender, EventArgs e) { PluginAppSettings.SetString("AutomaticUpdates", "False"); PluginUpdate.Check(); }