Christian Specht avatar Christian Specht committed 9cf2e9b

move config to user settings file, enter config data on startup
(fixes #6)

Comments (0)

Files changed (12)

 obj
 *.suo
 *.user
-App.config
 release
 *.wixobj
 *.wixpdb
 		</ItemGroup>
 		<Copy SourceFiles="@(ReleaseFiles)" DestinationFiles="@(ReleaseFiles -> '$(ReleaseDir)\%(RecursiveDir)%(Filename)%(Extension)')"/>
 
-		<!-- rename App.config.example to app.config -->
-		<Copy 
-			SourceFiles="$(ReleaseDir)\App.config.example" 
-			DestinationFiles="$(ReleaseDir)\BitbucketBackup.exe.config"/>	
-		<Delete Files="$(ReleaseDir)\App.config.example"/>
-
 	</Target>
 
 </Project>

src/BitbucketBackup/App.config

+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+
+  <configSections>
+    <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
+      <section name="BitbucketBackup.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
+    </sectionGroup>
+  </configSections>
+  
+  <userSettings>
+    <BitbucketBackup.Properties.Settings>
+      <setting name="UserName" serializeAs="String">
+        <value />
+      </setting>
+      <setting name="PassWord" serializeAs="String">
+        <value />
+      </setting>
+      <setting name="BackupFolder" serializeAs="String">
+        <value />
+      </setting>
+    </BitbucketBackup.Properties.Settings>
+  </userSettings>
+</configuration>

src/BitbucketBackup/App.config.example

-<?xml version="1.0" encoding="utf-8" ?>
-<configuration>
-
-  <appSettings>
-
-    <!-- Bitbucket user and password -->
-    <add key="User" value="Your_Username" />
-    <add key="Password" value="Your_Password" />
-
-    <!-- Folder on local machine where backups are saved -->
-    <add key="BackupFolder" value="c:\bitbucket-backup" />
-    
-  </appSettings>
-  
-</configuration>

src/BitbucketBackup/BitbucketBackup.csproj

     <Compile Include="GitRepository.cs" />
     <Compile Include="GitWrapper.cs" />
     <Compile Include="MercurialRepository.cs" />
+    <Compile Include="Properties\Settings.Designer.cs">
+      <AutoGen>True</AutoGen>
+      <DesignTimeSharedInput>True</DesignTimeSharedInput>
+      <DependentUpon>Settings.settings</DependentUpon>
+    </Compile>
     <Compile Include="RepositoryBase.cs" />
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="App.config" />
-    <None Include="App.config.example">
-      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    <None Include="Properties\Settings.settings">
+      <Generator>SettingsSingleFileGenerator</Generator>
+      <LastGenOutput>Settings.Designer.cs</LastGenOutput>
     </None>
   </ItemGroup>
   <ItemGroup>
   <!-- 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.
        -->
-  <Import Project="..\..\lib\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
+  <Import Project="..\..\lib\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
   <Target Name="BeforeBuild">
-	<PropertyGroup>
-		<ProdVer>0.0</ProdVer>
-	</PropertyGroup>
-	<PropertyGroup>
-		<ProdVer Condition="'$(VersionNumber)' != ''">$(VersionNumber)</ProdVer>
-	</PropertyGroup>
-  		<AssemblyInfo CodeLanguage="CS"
-			OutputFile="AssemblyVersion.cs"
-			AssemblyVersion="$(ProdVer)" 
-			AssemblyFileVersion="$(ProdVer)" />
-    <Copy Condition="!Exists('App.config')" SourceFiles="App.config.example" DestinationFiles="App.config" />
+    <PropertyGroup>
+      <ProdVer>0.0</ProdVer>
+    </PropertyGroup>
+    <PropertyGroup>
+      <ProdVer Condition="'$(VersionNumber)' != ''">$(VersionNumber)</ProdVer>
+    </PropertyGroup>
+    <AssemblyInfo CodeLanguage="CS" OutputFile="AssemblyVersion.cs" AssemblyVersion="$(ProdVer)" AssemblyFileVersion="$(ProdVer)" />
   </Target>
   <Target Name="AfterBuild">
   </Target>

src/BitbucketBackup/Config.cs

-using System.Configuration;
+using System;
+using BitbucketBackup.Properties;
 
 namespace BitbucketBackup
 {
         /// <summary>
         /// Bitbucket password
         /// </summary>
-        public string PassWord { get; private set; }
+        public string PassWord
+        {
+            get
+            {
+                return Settings.Default.PassWord;
+            }
+            private set
+            {
+                Settings.Default.PassWord = value;
+                Settings.Default.Save();
+            }
+
+        }
 
         /// <summary>
         /// Bitbucket username
         /// </summary>
-        public string UserName { get; private set; }
+        public string UserName
+        {
+            get
+            {
+                return Settings.Default.UserName;
+            }
+            private set
+            {
+                Settings.Default.UserName = value;
+                Settings.Default.Save();
+            }
+        }
 
         /// <summary>
         /// Folder on local machine where backups are saved
         /// </summary>
-        public string BackupFolder { get; private set; }
+        public string BackupFolder
+        {
+            get
+            {
+                return Settings.Default.BackupFolder;
+            }
+            private set
+            {
+                Settings.Default.BackupFolder = value;
+                Settings.Default.Save();
+            }
+        }
 
         /// <summary>
-        /// Creates a new Config object
+        /// Checks if the config is complete (if none of the settings is empty)
         /// </summary>
-        public Config()
+        public bool IsComplete
         {
-            this.UserName = ConfigurationManager.AppSettings["User"];
-            this.PassWord = ConfigurationManager.AppSettings["Password"];
-            this.BackupFolder = ConfigurationManager.AppSettings["BackupFolder"];
+            get
+            {
+                return this.UserName != string.Empty
+                    && this.PassWord != string.Empty
+                    && this.BackupFolder != string.Empty;
+            }
+        }
+
+        /// <summary>
+        /// Asks for the config settings
+        /// </summary>
+        public void Input()
+        {
+            Console.WriteLine(Resources.InputUser);
+            this.UserName = Console.ReadLine();
+
+            Console.WriteLine(Resources.InputPassword);
+            this.PassWord = Console.ReadLine();
+
+            Console.WriteLine(Resources.InputBackupFolder);
+            this.BackupFolder = Console.ReadLine();
         }
     }
 }

src/BitbucketBackup/Program.cs

     {
         static void Main(string[] args)
         {
-            int sleepTime = 2000;
+            int waitSeconds = 2;
+            int waitInputSeconds = 10;
 
             try
             {
 
                 Console.WriteLine(Resources.IntroHeadline, FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion);
                 Console.WriteLine();
+
+                bool enterConfig = false;
+
+                if (config.IsComplete)
+                {
+                    Console.WriteLine(Resources.SettingsPrompt, waitInputSeconds);
+                    Console.WriteLine();
+
+                    for (int seconds = 0; seconds < waitInputSeconds; seconds++)
+                    {
+                        if (Console.KeyAvailable)
+                        {
+                            ConsoleKeyInfo info = Console.ReadKey(true);
+                            if (info.Key == ConsoleKey.Spacebar)
+                            {
+                                enterConfig = true;
+                                break;
+                            }
+                        }
+
+                        Thread.Sleep(1000);
+                    }
+                }
+
+                if (enterConfig || !config.IsComplete)
+                {
+                    config.Input();
+                    Console.WriteLine();
+                }
+                
                 Console.WriteLine(Resources.IntroUser, config.UserName);
                 Console.WriteLine(Resources.IntroFolder, config.BackupFolder);
                 Console.WriteLine();
-                Thread.Sleep(sleepTime);
+                Thread.Sleep(waitSeconds * 1000);
 
                 var request = new BitbucketRequest(config);
 
 
                 Console.WriteLine();
                 Console.WriteLine(Resources.BackupCompleted);
-                Thread.Sleep(sleepTime);
+                Thread.Sleep(waitSeconds * 1000);
             }
             catch (ClientException ex)
             {

src/BitbucketBackup/Properties/Settings.Designer.cs

+//------------------------------------------------------------------------------
+// <auto-generated>
+//     Dieser Code wurde von einem Tool generiert.
+//     Laufzeitversion:4.0.30319.239
+//
+//     Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
+//     der Code erneut generiert wird.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace BitbucketBackup.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("")]
+        public string UserName {
+            get {
+                return ((string)(this["UserName"]));
+            }
+            set {
+                this["UserName"] = value;
+            }
+        }
+        
+        [global::System.Configuration.UserScopedSettingAttribute()]
+        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+        [global::System.Configuration.DefaultSettingValueAttribute("")]
+        public string PassWord {
+            get {
+                return ((string)(this["PassWord"]));
+            }
+            set {
+                this["PassWord"] = value;
+            }
+        }
+        
+        [global::System.Configuration.UserScopedSettingAttribute()]
+        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+        [global::System.Configuration.DefaultSettingValueAttribute("")]
+        public string BackupFolder {
+            get {
+                return ((string)(this["BackupFolder"]));
+            }
+            set {
+                this["BackupFolder"] = value;
+            }
+        }
+    }
+}

src/BitbucketBackup/Properties/Settings.settings

+<?xml version='1.0' encoding='utf-8'?>
+<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="BitbucketBackup.Properties" GeneratedClassName="Settings">
+  <Profiles />
+  <Settings>
+    <Setting Name="UserName" Type="System.String" Scope="User">
+      <Value Profile="(Default)" />
+    </Setting>
+    <Setting Name="PassWord" Type="System.String" Scope="User">
+      <Value Profile="(Default)" />
+    </Setting>
+    <Setting Name="BackupFolder" Type="System.String" Scope="User">
+      <Value Profile="(Default)" />
+    </Setting>
+  </Settings>
+</SettingsFile>

src/BitbucketBackup/Resources.Designer.cs

         }
         
         /// <summary>
+        ///   Sucht eine lokalisierte Zeichenfolge, die Local backup folder: ähnelt.
+        /// </summary>
+        internal static string InputBackupFolder {
+            get {
+                return ResourceManager.GetString("InputBackupFolder", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Sucht eine lokalisierte Zeichenfolge, die Your Bitbucket password: ähnelt.
+        /// </summary>
+        internal static string InputPassword {
+            get {
+                return ResourceManager.GetString("InputPassword", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Sucht eine lokalisierte Zeichenfolge, die Your Bitbucket username: ähnelt.
+        /// </summary>
+        internal static string InputUser {
+            get {
+                return ResourceManager.GetString("InputUser", resourceCulture);
+            }
+        }
+        
+        /// <summary>
         ///   Sucht eine lokalisierte Zeichenfolge, die Local backup folder: {0} ähnelt.
         /// </summary>
         internal static string IntroFolder {
                 return ResourceManager.GetString("PullingMercurial", resourceCulture);
             }
         }
+        
+        /// <summary>
+        ///   Sucht eine lokalisierte Zeichenfolge, die Press &lt;SPACE&gt; in the next {0} seconds to re-enter your settings! ähnelt.
+        /// </summary>
+        internal static string SettingsPrompt {
+            get {
+                return ResourceManager.GetString("SettingsPrompt", resourceCulture);
+            }
+        }
     }
 }

src/BitbucketBackup/Resources.de.resx

   <data name="ClientExceptionHeadline" xml:space="preserve">
     <value>Backup fehlgeschlagen!</value>
   </data>
+  <data name="InputBackupFolder" xml:space="preserve">
+    <value>Lokaler Backup-Ordner:</value>
+  </data>
+  <data name="InputPassword" xml:space="preserve">
+    <value>Ihr Bitbucket-Passwort:</value>
+  </data>
+  <data name="InputUser" xml:space="preserve">
+    <value>Ihr Bitbucket-Benutzername:</value>
+  </data>
   <data name="IntroFolder" xml:space="preserve">
     <value>Lokaler Backup-Ordner: {0}</value>
   </data>
   <data name="PressEnter" xml:space="preserve">
     <value>Drücken Sie &lt;ENTER&gt;, um das Programm zu beenden!</value>
   </data>
+  <data name="SettingsPrompt" xml:space="preserve">
+    <value>Drücken Sie &lt;LEERTASTE&gt; in den nächsten {0} Sekunden,
+um Ihre Einstellungen zu ändern!</value>
+  </data>
 </root>

src/BitbucketBackup/Resources.resx

   <data name="PullingGit" xml:space="preserve">
     <value>git pull: {0}</value>
   </data>
+  <data name="InputBackupFolder" xml:space="preserve">
+    <value>Local backup folder:</value>
+  </data>
+  <data name="InputPassword" xml:space="preserve">
+    <value>Your Bitbucket password:</value>
+  </data>
+  <data name="InputUser" xml:space="preserve">
+    <value>Your Bitbucket username:</value>
+  </data>
+  <data name="SettingsPrompt" xml:space="preserve">
+    <value>Press &lt;SPACE&gt; in the next {0} seconds to re-enter your settings!</value>
+  </data>
 </root>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.