private void initializeLearningTab() { // read key name mapping table KeyName[] keys = SettingFiles.LoadKeyListFromFile(); foreach (KeyName key in keys) { mKeyNameTable.Add(key.Id, key); } // init key name list view lvKeyList.Columns.Add(Resources.TITLE_KEY_ID, 200); lvKeyList.Columns.Add(Resources.TITLE_KEY_NAME, 100); lvKeyList.Columns.Add(Resources.TITLE_FORMAT_ID, 200); lvKeyList.Columns.Add(Resources.TITLE_CUSTOM_CODE, 100); lvKeyList.Columns.Add(Resources.TITLE_KEY_CODE, 100); progressBarLearning.Visible = false; // hide initially // init learning result list view lvResultList.Columns.Add(Resources.TITLE_FORMAT_ID, 150); lvResultList.Columns.Add(Resources.TITLE_CUSTOM_CODE, 80); lvResultList.Columns.Add(Resources.TITLE_KEY_CODE, -2); // add default keys AddDefaultLearningKeys(); if (lvKeyList.Items.Count > 0 && lvKeyList.SelectedIndices.Count == 0) { lvKeyList.Items[0].Selected = true; } mMyIrReader = Kit.createIRReader(Settings.Default.ALWAYS_PULL_DATA_FROM_CLOUD); }
private void FormKeyPicker_Load(object sender, EventArgs e) { // load category list file mTypeList = SettingFiles.LoadTypeListFromFile(); lvKeyList.Columns.Add("Key ID", 200); lvKeyList.Columns.Add("Key Name", -2); // init combobox TypeItem[] types = SettingFiles.LoadTypeListFromFile(); cboCategory.Items.Add(new TypeItem(GENERAL_TYPE_ID, Resources.ALL_CATEGORY, "A")); foreach (TypeItem type in types) { cboCategory.Items.Add(type); } String selectedCategoryId = Settings.Default.M_SELECTED_CATEGORY_ID; TypeItem tmpCategory; Boolean bFound = false; for (int i = 0; i < cboCategory.Items.Count; i++) { tmpCategory = (TypeItem)cboCategory.Items[i]; if (tmpCategory.Id.Equals(selectedCategoryId)) { cboCategory.SelectedIndex = i; bFound = true; break; } } if (!bFound) { cboCategory.SelectedIndex = 0; } }
private void DoInitDownload(object sender, DoWorkEventArgs e) { BackgroundWorker worker = (BackgroundWorker)sender; String languageCode = (String)e.Argument; int currentProgress = 0; worker.ReportProgress(currentProgress, Resources.I_DOWNLOADING_TYPES); if (worker.CancellationPending) { e.Cancel = true; return; } // get types TypeItem[] types = Web.getTypeList(languageCode, mGetNew, null); SettingFiles.SaveTypeListToFile(types); // get brands int progressPartForBrand = 40 / types.Length; int progressPartForKey = 40 / types.Length; int progressPartForIrReader = 20; BrandItem[] brands; Dictionary <String, KeyName> keyMap = new Dictionary <String, KeyName>(); for (int i = 0; i < types.Length; i++) { if (worker.CancellationPending) { e.Cancel = true; return; } currentProgress += progressPartForBrand; worker.ReportProgress(currentProgress, String.Format(Resources.I_DOWNLOADING_BRANDS + " {0}/{1}", i + 1, types.Length)); brands = Web.getBrandList(types[i].Id, 0, 2000, languageCode, null, mGetNew, null); if (null != brands) { SettingFiles.SaveBrandListToFile(types[i].Id, brands); } else { e.Result = false; return; } if (worker.CancellationPending) { e.Cancel = true; return; } currentProgress += progressPartForKey; worker.ReportProgress(currentProgress, String.Format(Resources.I_DOWNLOADING_KEYS + " {0}/{1}", i + 1, types.Length)); KeyName[] keys = Web.getKeyName(types[i].Id, languageCode, mGetNew, null); if (null != keys) { foreach (KeyName key in keys) { if (!keyMap.ContainsKey(key.Id)) { keyMap.Add(key.Id, key); } } } else { e.Result = false; return; } } if (worker.CancellationPending) { e.Cancel = true; return; } currentProgress += progressPartForIrReader / 2; worker.ReportProgress(currentProgress, Resources.I_DOWNLOADING_FORMATS); // IRReader IRReader irReader = Kit.createIRReader(mGetNew); if (null == irReader) { e.Result = false; return; } worker.ReportProgress(100, Resources.COMPLETED); List <KeyName> keyList = new List <KeyName>(); foreach (KeyValuePair <String, KeyName> entry in keyMap) { keyList.Add(entry.Value); } if (keyList.Count > 0) { SettingFiles.SaveKeyListToFile(keyList.ToArray()); } else { e.Result = false; return; } e.Result = true; }