Permalink
Browse files

Added settings to project

Updated .gitignore to include *.vs10x
Updated program to include use of new settings.
Added ability to display last used information for command and connection info.
Fix for exitrcon showing up as last used rcon command.
Saving is always done just before quit question (make sure we always save the data)
  • Loading branch information...
1 parent 96ac89f commit aa51e6f46c3ae96be9f45c55be5cb0843dbad751 @jaddie committed Sep 30, 2010
Showing with 165 additions and 18 deletions.
  1. +2 −1 .gitignore
  2. +14 −1 Cod4RconConsoleTool.csproj
  3. +33 −16 Program.cs
  4. +74 −0 Properties/Settings.Designer.cs
  5. +18 −0 Properties/Settings.settings
  6. +24 −0 app.config
View
@@ -31,4 +31,5 @@ Thumbs.db
obj/
[Rr]elease*/
_ReSharper*/
-[Tt]est[Rr]esult*
+[Tt]est[Rr]esult*
+*.vs10x
@@ -11,7 +11,8 @@
<RootNamespace>Cod4RconConsoleTool</RootNamespace>
<AssemblyName>Cod4RconConsoleTool</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
- <TargetFrameworkProfile>Client</TargetFrameworkProfile>
+ <TargetFrameworkProfile>
+ </TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
@@ -45,8 +46,20 @@
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="Properties\Settings.Designer.cs">
+ <AutoGen>True</AutoGen>
+ <DesignTimeSharedInput>True</DesignTimeSharedInput>
+ <DependentUpon>Settings.settings</DependentUpon>
+ </Compile>
<Compile Include="ScheduleHandler.cs" />
</ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="Properties\Settings.settings">
+ <Generator>SettingsSingleFileGenerator</Generator>
+ <LastGenOutput>Settings.Designer.cs</LastGenOutput>
+ </None>
+ </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
View
@@ -4,7 +4,7 @@
using System.Net;
using System.Net.Sockets;
using System.Text;
-
+using Settings = Cod4RconConsoleTool.Properties.Settings;
namespace Cod4RconConsoleTool
{
class Program
@@ -18,46 +18,58 @@ static void Main(string[] args)
{
try
{
+ if (!string.IsNullOrEmpty(Settings.Default.IP.ToString()))
+ IP = IPAddress.Parse(Settings.Default.IP);
+ if (!string.IsNullOrEmpty(Settings.Default.Port.ToString()))
+ Port = Settings.Default.Port;
+ if (!string.IsNullOrEmpty(Settings.Default.RconPassword))
+ RconPassword = Settings.Default.RconPassword;
+ if (!string.IsNullOrEmpty(Settings.Default.RconCommand))
+ RconCommand = Settings.Default.RconCommand;
if (IP != null && Port != 0 && RconPassword != null && RconCommand != null)
{
- Console.WriteLine("Would you like to use your previous information? - Please enter yes or no");
+ Console.WriteLine("Would you like to use your previous information?\nAs Follows:\n{0}\n{1}\n{2}\nPlease enter yes or no",IP,Port,RconPassword);
if (Console.ReadLine().ToLower() == "yes")
{
if (!string.IsNullOrEmpty(RconCommand))
{
- Console.WriteLine("Would you like to run the same command again? - yes or no");
+ Console.WriteLine("Would you like to run the last used command again?\n{0} - yes or no",RconCommand);
if(Console.ReadLine().ToLower() == "yes")
{
Console.WriteLine("Executing previous command...");
Console.WriteLine(Rcon(IP, Port, RconPassword, RconCommand));
- return;
}
else
{
Console.WriteLine("Enter command to execute");
RconCommand = Console.ReadLine();
Console.WriteLine(Rcon(IP, Port, RconPassword, RconCommand));
- return;
}
}
}
+ else
+ {
+ Console.WriteLine("Enter IP");
+ IP = IPAddress.Parse(Console.ReadLine());
+ Console.WriteLine("Enter Port");
+ Port = int.Parse(Console.ReadLine());
+ Console.WriteLine("Enter RCon Password");
+ RconPassword = Console.ReadLine();
+ Console.WriteLine("Enter RCon Command To Run");
+ RconCommand = Console.ReadLine();
+ Console.WriteLine("Connecting..");
+ Console.WriteLine(Rcon(IP, Port, RconPassword, RconCommand));
+ }
}
- Console.WriteLine("Enter IP");
- IP = IPAddress.Parse(Console.ReadLine());
- Console.WriteLine("Enter Port");
- Port = int.Parse(Console.ReadLine());
- Console.WriteLine("Enter RCon Password");
- RconPassword = Console.ReadLine();
- Console.WriteLine("Enter RCon Command To Run");
- RconCommand = Console.ReadLine();
- Console.WriteLine("Connecting..");
- Console.WriteLine(Rcon(IP, Port, RconPassword, RconCommand));
Console.WriteLine("Command Executed, you are now at an rcon terminal\n(in english you can now just type commands to be sent directly do not put rcon at the start)\nIt will be added automaticlly for you.\nTo close the program type exitrcon");
- var input = "";
+ var input = "";
while (input.ToLower() != "exitrcon")
{
input = Console.ReadLine();
+ if (input == "exitrcon")
+ return;
+ RconCommand = input;
Console.WriteLine(Rcon(IP, Port, RconPassword, input));
}
}
@@ -69,6 +81,11 @@ static void Main(string[] args)
}
finally
{
+ Settings.Default.IP = IP.ToString();
+ Settings.Default.Port = Port;
+ Settings.Default.RconPassword = RconPassword;
+ Settings.Default.RconCommand = RconCommand;
+ Settings.Default.Save();
Console.WriteLine("Program finished,press enter to exit or enter r to start from the beginning again");
var reply = Console.ReadLine();
if (reply.ToLower() == "r")
@@ -0,0 +1,74 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.1
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace Cod4RconConsoleTool.Properties {
+
+
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
+ internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
+
+ private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
+
+ public static Settings Default {
+ get {
+ return defaultInstance;
+ }
+ }
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("0")]
+ public string IP {
+ get {
+ return ((string)(this["IP"]));
+ }
+ set {
+ this["IP"] = value;
+ }
+ }
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("0")]
+ public int Port {
+ get {
+ return ((int)(this["Port"]));
+ }
+ set {
+ this["Port"] = value;
+ }
+ }
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("")]
+ public string RconPassword {
+ get {
+ return ((string)(this["RconPassword"]));
+ }
+ set {
+ this["RconPassword"] = value;
+ }
+ }
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("")]
+ public string RconCommand {
+ get {
+ return ((string)(this["RconCommand"]));
+ }
+ set {
+ this["RconCommand"] = value;
+ }
+ }
+ }
+}
@@ -0,0 +1,18 @@
+<?xml version='1.0' encoding='utf-8'?>
+<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="Cod4RconConsoleTool.Properties" GeneratedClassName="Settings">
+ <Profiles />
+ <Settings>
+ <Setting Name="IP" Type="System.String" Scope="User">
+ <Value Profile="(Default)">0</Value>
+ </Setting>
+ <Setting Name="Port" Type="System.Int32" Scope="User">
+ <Value Profile="(Default)">0</Value>
+ </Setting>
+ <Setting Name="RconPassword" Type="System.String" Scope="User">
+ <Value Profile="(Default)" />
+ </Setting>
+ <Setting Name="RconCommand" Type="System.String" Scope="User">
+ <Value Profile="(Default)" />
+ </Setting>
+ </Settings>
+</SettingsFile>
View
@@ -0,0 +1,24 @@
+<?xml version="1.0"?>
+<configuration>
+<configSections>
+ <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
+ <section name="Cod4RconConsoleTool.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
+ </sectionGroup>
+</configSections>
+<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup><userSettings>
+ <Cod4RconConsoleTool.Properties.Settings>
+ <setting name="IP" serializeAs="String">
+ <value>0</value>
+ </setting>
+ <setting name="Port" serializeAs="String">
+ <value>0</value>
+ </setting>
+ <setting name="RconPassword" serializeAs="String">
+ <value />
+ </setting>
+ <setting name="RconCommand" serializeAs="String">
+ <value />
+ </setting>
+ </Cod4RconConsoleTool.Properties.Settings>
+ </userSettings>
+</configuration>

0 comments on commit aa51e6f

Please sign in to comment.