Exemplo n.º 1
0
        public static void saveSettings()
        {
            List <KeyValuePair <string, string> > lout = new List <KeyValuePair <string, string> >();

            for (int i = 0; i < defsetting.Count; i++)
            {
                lout.Add(new KeyValuePair <string, string>(defsetting[i].Key, settings[defsetting[i].Key]));
            }
            ZDictionaryFileIO.writeFile(lout, Localization.Settings.Symbol_NameContent_Seperator, FILE_NAME);
        }
Exemplo n.º 2
0
        public void writeFile(string absolutePath, CultureInfo lang)
        {
            IOUtil.inLocalizedEnviroment(lang, () =>
            {
                string sep   = Localization.Settings.Symbol_NameContent_Seperator;
                string fname = Localization.FileKeywords.FileName_CardBoxInfo + "." + lang.Name + "." + SystemResources.Postfix_File;

                List <KeyValuePair <string, string> > odata = new List <KeyValuePair <string, string> >();
                odata.Add(new KeyValuePair <string, string>(Localization.FileKeywords.CardBox_Title, title));
                odata.Add(new KeyValuePair <string, string>(Localization.FileKeywords.CardBox_Creater, creator));
                odata.Add(new KeyValuePair <string, string>(Localization.FileKeywords.CardBox_DateCreated, dateCreated));
                odata.Add(new KeyValuePair <string, string>(Localization.FileKeywords.CardBox_Index, zu.OtherIfNull(BoxIndexingHandler.getIndexingText(indexing), getDefaults(lang.Name)[Localization.FileKeywords.CardBox_Index])));
                string schapters = "";
                for (int i = 0; i < chapters.Count; i++)
                {
                    schapters += chapters[i] + sep;
                }
                odata.Add(new KeyValuePair <string, string>(Localization.FileKeywords.CardBox_ChapterNames, schapters));
                string scategories = "";
                foreach (string s in categories)
                {
                    scategories += s + sep;
                }
                odata.Add(new KeyValuePair <string, string>(Localization.FileKeywords.CardBox_CategoryNames, scategories));
                string skeywords = "";
                foreach (string s in keywords)
                {
                    skeywords += s + sep;
                }
                odata.Add(new KeyValuePair <string, string>(Localization.FileKeywords.CardBox_KeywordNames, skeywords));
                odata.Add(new KeyValuePair <string, string>(Localization.FileKeywords.CardBox_Description, description));

                //first deal with file's date, if the file is newly created. Else leave it to default handling
                if (dateCreated.Trim() == "" && !File.Exists(Path.Combine(absolutePath, fname)))
                {
                    dateCreated = IOUtil.formatNow();
                }

                //ensures there's a default for this language
                getDefaults(lang.Name);

                for (int i = 0; i < odata.Count; i++)
                {//add defaults to empy attributes
                    KeyValuePair <string, string> p = odata[i];
                    if (langDefaults[lang.Name].ContainsKey(p.Key) && p.Value == "")
                    {
                        odata[i] = new KeyValuePair <string, string>(p.Key, langDefaults[lang.Name][p.Key]);
                    }
                }

                ZDictionaryFileIO.writeFile(odata, sep, absolutePath, fname);
            });
        }
Exemplo n.º 3
0
        static SettingsFileData()
        {
            defsetting = new List <KeyValuePair <string, string> >();
            defsetting.Add(new KeyValuePair <string, string>(Localization.FileKeywords.Settings_CurrentLanguage,
                                                             Thread.CurrentThread.CurrentUICulture.Name));
            defsetting.Add(new KeyValuePair <string, string>(Localization.FileKeywords.Settings_UsersName,
                                                             Localization.Settings.Defaults_UsersName));
            defsetting.Add(new KeyValuePair <string, string>(Localization.FileKeywords.Settings_DefaultCardBoxIndex,
                                                             DEFAULT_INDEXING));
            defsetting.Add(new KeyValuePair <string, string>(Localization.FileKeywords.Settings_LastPath, ""));

            if (!File.Exists(FILE_NAME))
            {
                ZDictionaryFileIO.writeFile(defsetting, Localization.Settings.Symbol_NameContent_Seperator, FILE_NAME);
            }

            settings = new Dictionary <string, string>();
            List <KeyValuePair <string, string> > fsettings = ZDictionaryFileIO.readFile(Localization.Settings.Symbol_NameContent_Seperator, FILE_NAME);

            foreach (KeyValuePair <string, string> l in fsettings)
            {
                settings.Add(l.Key, l.Value);
            }

            bool fileChanged = false;

            foreach (KeyValuePair <string, string> l in defsetting)
            {
                if (!settings.ContainsKey(l.Key))
                {
                    settings.Add(l.Key, l.Value);
                    fileChanged = true;
                }
            }
            if (!CardBoxFileData.isValidIndex(settings[Localization.FileKeywords.Settings_DefaultCardBoxIndex]))
            {
                settings[Localization.FileKeywords.Settings_DefaultCardBoxIndex] = DEFAULT_INDEXING;
            }
            if (fileChanged)
            {
                saveSettings();
            }

            listeners = new Dictionary <string, onSettingChanged>();
        }