Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="BoxDirectory">This should be the directory that contains the box info file and boxname.qnote folder.</param>
        public CardBoxTree(string boxDirectory)
            : this()
        {
            this.boxDirectory = boxDirectory;
            this.boxData      = CardBoxFileData.readFile(new FileReadingAdapter(), boxDirectory);

            contentDirectory = Path.Combine(boxDirectory, IOUtil.getContentFolderName(boxData.lang));
        }
Exemplo n.º 2
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>();
        }
Exemplo n.º 3
0
        public static string getCardParentFolderName(CardBoxFileData box, CardFileData card)
        {
            switch (box.indexing)
            {
            case BoxIndexing.CATEGORY:
                return(card.category);

            case BoxIndexing.CHAPTERS:
                return(string.Format(IOUtil.inLocalizedEnviroment(box.lang,
                                                                  () => Localization.FileKeywords.FileName_ChapterFolderPrefix +
                                                                  Localization.Settings.Symbol_NameContent_Seperator),
                                     box.chapters.IndexOf(card.chapterName) + 1) + card.chapterName);//cause it starts at 0!

            case BoxIndexing.CHRONOLOGICAL:
                return(card.dateCreated);
            }
            return(null);
        }
Exemplo n.º 4
0
        public static CardBoxFileData readFile(FileReadingOverseer overseer, string absolutePath)
        {
            string bfname = IOUtil.Delegated_GetApplicableFileWithFeedback(overseer, absolutePath);
            string flang  = IOUtil.getFileLang(bfname);

            CultureInfo stack = Thread.CurrentThread.CurrentUICulture;

            Thread.CurrentThread.CurrentUICulture = new CultureInfo(flang);

            List <KeyValuePair <string, string> > fdata = ZDictionaryFileIO.readFile(Localization.Settings.Symbol_NameContent_Seperator, absolutePath, bfname);

            //construct a set of file attributes that we want to ensure they are there and cross them off so its linear time to number of lines
            HashSet <string> missingfields = IOUtil.CheckFDataHaveAllDefaults(fdata, getDefaults(flang));

            if (missingfields.Count > 0)
            {
                Thread.CurrentThread.CurrentUICulture = stack;
                Instruction i = overseer.onFileInvalid(Localization.Messages.FileIO_FieldMissing, missingfields.ToArray());
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(flang);

                // TODO: Process the instruction
            }
            //now the file should have all nesscairy properties.

            CardBoxFileData cbd = new CardBoxFileData();

            cbd.lang = flang;
            foreach (var entry in fdata)
            {
                string att = entry.Key;
                string val = entry.Value;

                if (att == Localization.FileKeywords.CardBox_Title)
                {
                    cbd.title = val;
                }
                else if (att == Localization.FileKeywords.CardBox_Description)
                {
                    cbd.description = val;
                }
                else if (att == Localization.FileKeywords.CardBox_Creater)
                {
                    cbd.creator = val;
                }
                else if (att == Localization.FileKeywords.CardBox_DateCreated)
                {
                    cbd.dateCreated = val;
                }
                else if (att == Localization.FileKeywords.CardBox_Index)
                {
                    cbd.indexing = BoxIndexingHandler.getIndexingEnum(val);
                }
                else if (att == Localization.FileKeywords.CardBox_CategoryNames)
                {
                    cbd.categories = new SortedSet <string>();
                    cbd.categories.UnionWith(zusp.Split(val, Localization.Settings.Symbol_NameContent_Seperator).ToList());
                }
                else if (att == Localization.FileKeywords.CardBox_ChapterNames)
                {
                    cbd.chapters = zusp.Split(val, Localization.Settings.Symbol_NameContent_Seperator).ToList();
                }
                else if (att == Localization.FileKeywords.CardBox_KeywordNames)
                {
                    cbd.keywords = new HashSet <string>();
                    cbd.keywords.UnionWith(zusp.Split(val, Localization.Settings.Symbol_NameContent_Seperator).ToList());
                }
            }

            if (cbd.indexing == BoxIndexing.INVALID)
            {
                string flindex = Localization.FileKeywords.CardBox_Index;
                Thread.CurrentThread.CurrentUICulture = stack;
                Instruction i = overseer.onFileInvalid(Localization.Messages.FileIO_FieldValueNotValid, flindex);
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(flang);
            }
            Thread.CurrentThread.CurrentCulture = stack;
            return(cbd);
        }