Пример #1
0
        private void SyncLangFile(LanguageFile lFileEng, LanguageFile lFileSync)
        {
            bool changed = false;

            foreach (EasyPropertiesNode nodeEng in lFileEng.Ps.GetChildProperties())
            {
                if (nodeEng.Name.Equals(LanguageFile.LANGUAGE_PROPERTIES_NODE_NAME))
                {
                    continue;
                }

                EasyPropertiesNode            nodeSync = lFileSync.Ps[nodeEng.Name];
                EasyPropertiesNode.Property[] valsEng  = nodeEng.GetValues();

                foreach (EasyPropertiesNode.Property valEng in valsEng)
                {
                    if (nodeSync.ContainsProperty(valEng.Name))
                    {
                        continue;
                    }
                    changed = true;
                    nodeSync.SetValue <string>(valEng.Name, (string)valEng.Value);
                }
            }
            if (!changed)
            {
                return;
            }
            lFileSync.Save();
        }
Пример #2
0
        public void Select(string code)
        {
            //if (_current != null) {
            //  if (code == _current.Code)
            //    return;

            //  this.Save();
            //  _current = null;
            //}

            _modify = false;
            bool isNew = !_languages.ContainsKey(code);

            _current = new LanguageFile(code, this._languagesDirectory);
            if (isNew)
            {
                this.Refresh();
                this.SyncLanguagePhrases();
                _current.ReLoad();
            }
            _current.File.Refresh();
            _currentModifyTime = _current.File.LastWriteTime;

            if (isNew)
            {
            }
        }
Пример #3
0
        private void Refresh()
        {
            FileInfo[] files  = _languagesDirectory.GetFiles("*." + LanguageManager.FILE_EXT);
            bool       update = !_listFile.Exists;

            foreach (FileInfo file in files)
            {
                string code = Path.GetFileNameWithoutExtension(file.FullName);
                if (!_languages.ContainsKey(code))
                {
                    update = true;
                    break;
                }
            }
            if (!update)
            {
                List <LanguageInfo> list = this.Read();
                foreach (LanguageInfo li in list)
                {
                    string code = Path.GetFileNameWithoutExtension(_listFile.FullName);
                    if (!code.Equals(li.Code))
                    {
                        update = true;
                        break;
                    }
                }
            }
            if (!update)
            {
                return;
            }

            if (_listFile.Exists)
            {
                _listFile.Delete();
            }

            using (FileStream fs = _listFile.Create()) {
                TextWriter tw = new StreamWriter(fs);

                foreach (FileInfo file in files)
                {
                    LanguageFile lfile = new LanguageFile(file);
                    tw.WriteLine(string.Format("{0},{1},{2}", lfile.Code, lfile.DisplayName, lfile.EnglishName));
                }
                tw.Flush();
                fs.Close();
            }
            _listFile.Refresh();
            this.Load();
        }
Пример #4
0
        public void SyncLanguagePhrases()
        {
            if (this._languages.Count <= 1)
            {
                return;
            }

            string engCode = "en-US";

            #region Auto Select from date
            /* Auto Select from date */
            //LanguageInfo[] currentLangFiles = this.ReLoad();
            //LanguageInfo lastModifyLangInfoFile = null;
            //foreach (LanguageInfo li in currentLangFiles) {
            //  if (lastModifyLangInfoFile == null) {
            //    lastModifyLangInfoFile = li;
            //    continue;
            //  }
            //  FileInfo actualFile = LanguageFile.CreateFile(lastModifyLangInfoFile.Code, _languagesDirectory);
            //  FileInfo currentFile = LanguageFile.CreateFile(li.Code, _languagesDirectory);

            //  if (currentFile.LastWriteTime > actualFile.LastWriteTime)
            //    lastModifyLangInfoFile = li;
            //}
            //engCode = lastModifyLangInfoFile.Code;
            #endregion

            LanguageFile lActualEngFile = new LanguageFile(engCode, this._languagesDirectory);

            foreach (LanguageInfo li in _languages.Values)
            {
                if (li.Code.Equals(engCode))
                {
                    continue;
                }

                LanguageFile lfile = new LanguageFile(li.Code, this._languagesDirectory);
                this.SyncLangFile(lActualEngFile, lfile);
            }
        }