From d17a8b557eecfcecbbccd3132f06db122ca0061a Mon Sep 17 00:00:00 2001 From: nishiki Date: Sun, 27 Apr 2014 18:53:20 +0200 Subject: [PATCH] add a directory conf --- MPW/Config.rb | 19 +++++++++++++++---- MPW/UI/Cli.rb | 2 +- i18n/cli/en.yml | 2 +- i18n/cli/fr.yml | 2 +- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/MPW/Config.rb b/MPW/Config.rb index 4a3b6b1..9f6d4a1 100644 --- a/MPW/Config.rb +++ b/MPW/Config.rb @@ -27,13 +27,22 @@ module MPW attr_accessor :sync_pwd attr_accessor :sync_path attr_accessor :last_update + attr_accessor :dir_config # Constructor # @args: file_config -> the specify config file def initialize(file_config=nil) - @error_msg = nil - @file_config = "#{Dir.home}/.mpw.cfg" - + @error_msg = nil + + if /darwin/ =~ RUBY_PLATFORM + @dir_config = "#{Dir.home}/Library/Preferences/mpw" + elsif /cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM + @dir_config = "#{Dir.home}/AppData/Local/mpw" + else + @dir_config = "#{Dir.home}/.config/mpw" + end + + @file_config = "#{@dir_config}/conf/default.cfg" if !file_config.nil? && !file_config.empty? @file_config = file_config end @@ -64,7 +73,7 @@ module MPW end if file_gpg.empty? - file_gpg = "#{Dir.home}/.mpw.gpg" + file_gpg = "#{@dir_config}/db/default.gpg" end timeout_pwd = timeout_pwd.empty? ? 60 : timeout_pwd.to_i @@ -82,6 +91,8 @@ module MPW 'sync_path' => sync_path, 'last_update' => 0 }} + Dir.mkdir("#{@config_dir}/conf", 700) + Dir.mkdir("#{@config_dir}/db", 700) File.open(@file_config, 'w') do |file| file << config.to_yaml end diff --git a/MPW/UI/Cli.rb b/MPW/UI/Cli.rb index cb49464..58fa371 100644 --- a/MPW/UI/Cli.rb +++ b/MPW/UI/Cli.rb @@ -77,7 +77,7 @@ class Cli language = ask(I18n.t('form.setup.lang', :lang => lang)).to_s key = ask(I18n.t('form.setup.gpg_key')).to_s share_keys = ask(I18n.t('form.setup.share_gpg_keys')).to_s - file_gpg = ask(I18n.t('form.setup.gpg_file', :home => Dir.home)).to_s + file_gpg = ask(I18n.t('form.setup.gpg_file', :home => @conf.dir_home)).to_s timeout_pwd = ask(I18n.t('form.setup.timeout')).to_s sync_type = ask(I18n.t('form.setup.sync_type')).to_s diff --git a/i18n/cli/en.yml b/i18n/cli/en.yml index e8f7d16..0a4c03a 100644 --- a/i18n/cli/en.yml +++ b/i18n/cli/en.yml @@ -73,7 +73,7 @@ en: lang: "Choose your language (en, fr, ...): " gpg_key: "Enter the GPG key: " share_gpg_keys: "Enter the GPG keys with who you want to share the passwords: " - gpg_file: "Enter the path to encrypt file [default=%{home}/.mpw.gpg]: " + gpg_file: "Enter the path to encrypt file [default=%{home}/db/default.gpg]: " timeout: "Enter the timeout (in seconde) to GPG password [default=60]: " sync_type: "Synchronization type (mpw, ssh, ftp, or nil): " sync_host: "Synchronization server: " diff --git a/i18n/cli/fr.yml b/i18n/cli/fr.yml index bb5491d..1640cb7 100644 --- a/i18n/cli/fr.yml +++ b/i18n/cli/fr.yml @@ -73,7 +73,7 @@ fr: lang: "Choisissez votre langue (en, fr, ...) [défaut=%{lang}]: " gpg_key: "Entrez la clé GPG: " share_gpg_keys: "Entrez les clés GPG avec qui vous voulez partager les mots de passe: " - gpg_file: "Entrez le chemin du fichier qui sera chiffré [défaut=%{home}/.mpw.gpg]: " + gpg_file: "Entrez le chemin du fichier qui sera chiffré [défaut=%{home}/db/default.gpg]: " timeout: "Entrez le temps (en seconde) du mot de passe GPG [défaut=60]: " sync_type: "Type de synchronisation (mpw, ssh, ftp, or nil): " sync_host: "Serveur de synchronisation: "