public void SaveSettingsFileInfo(SettingsFileInfo info) { string settingspath = Environment.GetEnvironmentVariable("LocalAppData") + "\\Cura\\bin\\settings.cura"; if (File.Exists(settingspath)) { File.Delete(settingspath); } TextWriter fstream = File.CreateText(settingspath); fstream.WriteLine("<settings>"); fstream.WriteLine("<datafilepath>" + info._datafilepath + "</datafilepath>"); fstream.WriteLine("<securitykey>" + info._securitykey + "</securitykey>"); fstream.WriteLine("<firstweek>" + info._firstweek.ToString("yyyy-MM-dd") + "</firstweek>"); fstream.WriteLine("<rotarange>" + info._rotarange.ToString() + "</rotarange>"); fstream.WriteLine("<rotaweekcount>" + info._rotaweekcount.ToString() + "</rotaweekcount>"); fstream.WriteLine("<displaycallwithtraveltime>" + info._displaycallwithtraveltime.ToString() + "</displaycallwithtraveltime>"); fstream.WriteLine("</settings>"); fstream.Close(); }
private void mergeBtn_Click(object sender, EventArgs e) { mergeBtn.Enabled = false; Cursor = Cursors.WaitCursor; try { //ok lets get the cura directory string curaDirectory = oldcurapathtxt.Text; string settingsDirectory = curaDirectory + '\\' + "settings.cura"; //get settings SettingsFileInfo inf = LoadSettingsFileInfo(settingsDirectory); int index = inf._datafilepath.LastIndexOf("\\") + 1; string datafilename = inf._datafilepath.Substring(index, inf._datafilepath.Length - index); string newlocation = null; //move data file? if (datakeepRadio.Checked) { //keep data in the same place, dont really need to do anything. newlocation = inf._datafilepath; } else if (newCuralocationRadio.Checked) { newlocation = Environment.GetEnvironmentVariable("LocalAppData") + "\\Cura\\data\\" + datafilename; //copy data file to current Cura data folder File.Copy(inf._datafilepath, newlocation, true); } else if (newlocationRadio.Checked) { //get the location for new cura data file location newlocation = datafiletxt.Text + "\\" + datafilename; //copy old data file to new location File.Copy(inf._datafilepath, newlocation); } inf._datafilepath = newlocation; //save settings to new cura folder SaveSettingsFileInfo(inf); //delete old cura? if (checkBox1.Checked) { Directory.Delete(curaDirectory, true); } MessageBox.Show("Merge Completed Successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("An Error Occured During Merge : \r\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);; } Cursor = Cursors.Default; mergeBtn.Enabled = true; }
/// <summary> /// Load Settings From A Cura Settings File /// </summary> /// <param name="settingsFilePath"></param> /// <returns></returns> public SettingsFileInfo LoadSettingsFileInfo(string settingsFilePath) { SettingsFileInfo sfi = new SettingsFileInfo(); if (!File.Exists(settingsFilePath)) { return(null); } String fData = ""; try { using (StreamReader infile = new StreamReader(settingsFilePath)) { fData = infile.ReadToEnd(); } } catch (Exception ex) { /* Couldnt log it, oh well just show the error message form */ return(null); } XmlReader reader = XmlReader.Create(new StringReader(fData)); #region ReadXML bool foundsettings = false; try { while (reader.Read()) { if (reader.IsStartElement()) { switch (reader.Name) { case "settings": foundsettings = true; while (reader.Read()) { if (reader.IsStartElement()) { switch (reader.Name) { case "datafilepath": if (reader.Read()) { sfi._datafilepath = reader.Value.Trim(); } break; case "securitykey": if (reader.Read()) { sfi._securitykey = reader.Value.Trim(); } break; case "firstweek": if (reader.Read()) { sfi._firstweek = DateTime.ParseExact(reader.Value.Trim(), "yyyy-MM-dd", CultureInfo.InvariantCulture); } break; case "rotarange": if (reader.Read()) { sfi._rotarange = Convert.ToInt16(reader.Value.Trim()); } break; case "rotaweekcount": if (reader.Read()) { sfi._rotaweekcount = Convert.ToInt16(reader.Value.Trim()); } break; case "displaycallwithtraveltime": if (reader.Read()) { sfi._displaycallwithtraveltime = Convert.ToBoolean(reader.Value.Trim()); } break; } } else if (reader.Name == "settings") { break; // TODO: might not be correct. Was : Exit While } } break; } } } } catch (Exception e) { //couldnt open the file, lets create it instead. return(null); } #endregion return(sfi); }