public static void LoadConfigFromFile() { var dir = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); if (string.IsNullOrWhiteSpace(dir)) { return; } var filePath = Path.Combine(dir, ConfigFileName); if (!File.Exists(filePath)) { return; } var str = HttpHandlers.WriteSafeReadAllLines(filePath); if (!string.IsNullOrWhiteSpace(str)) { //var a = JObject.Parse(str); //var url = (string) a["serverUrl"]; //if (!string.IsNullOrWhiteSpace(url)) //{ // ServerUrl = url; //} var des = (ProgramConfigJSON)JsonConvert.DeserializeObject(str, typeof(ProgramConfigJSON)); configJSON = des; ServerUrl = configJSON.serverURL; if (!string.IsNullOrWhiteSpace(configJSON.account)) { Account = configJSON.account; } if (!string.IsNullOrWhiteSpace(configJSON.password)) { Password = configJSON.password; } } }
private void OnLoad_Button_Clicked(object sender, RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.FileName = "origin"; // Default file name dlg.DefaultExt = ".csv"; // Default file extension dlg.Filter = "CSV documents (.csv)|*.csv"; // Filter files by extension // Show open file dialog box bool?result = dlg.ShowDialog(); // Process open file dialog box results if (result == true) { try { var x = HttpHandlers.WriteSafeReadAllLines(dlg.FileName); if (!string.IsNullOrWhiteSpace(x)) { using (var stringReader = new StringReader(x)) { // csv reader var csvReader = new CsvReader(stringReader); var expectedHeaders = MyCsvHeaders.GetHeaders(_gameType); // 读取头部 if (!csvReader.ReadHeader()) { MessageBox.Show("Invalid input csv file, no record found"); return; } if (expectedHeaders.Length != csvReader.FieldHeaders.Length) { MessageBox.Show("Invalid input csv file, header count not match"); return; } for (var i = 0; i < expectedHeaders.Length; i++) { if (string.Compare(expectedHeaders[i], csvReader.FieldHeaders[i], StringComparison.Ordinal) != 0) { MessageBox.Show("Invalid input csv file, header not match"); return; } } while (csvReader.Read()) { for (var i = 0; i < 4; i++) { var dealCfg = _dealCfgs[i]; dealCfg.ReadCsv(csvReader); dealCfg.Tiles2Ui(); } _drawCfg.ReadCsv(csvReader); _drawCfg.Tiles2Ui(); WallTiles2Ui(); // 仅读取第一个记录 break; } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }