public static Machines InitMachines(string path) { try { Machines myMachines = new Machines(); App.ExtractEmbeddedResources(".template", path); if (File.Exists(Path.Combine(path, LocalSettings.PublicSettingsFile))) { myMachines = myMachines.DeserializeXML(path); } else { Machine _machine = new Machine(); _machine.Projects = new List <Project>(); for (int i = 0; i < _machine.MaxToolRange; i++) { Project _project = new Project(i); _machine.Projects.Add(_project); } myMachines.Add(_machine); myMachines.SerializeXML(path); } foreach (var machine in myMachines) { if (machine.ControlVersion == Machine.TNCVersions.ab_TNC640) { LocalSettings myLocalSettings = new LocalSettings(); //MessageBox.Show("Das Verwenden der Einstellung 'ab_TNC640' setzt folgendes Paket voraus:\n\n'Microsoft Visual C++ 2010 Redistributable Package (x64)'", "Informtion", MessageBoxButtons.OK, MessageBoxIcon.Information); App.ExtractEmbeddedResources(".dll", myLocalSettings.LocalSettingsDirectory); App.ExtractEmbeddedResources("TNCSyncPlus.exe", myLocalSettings.LocalSettingsDirectory); break; } } return(myMachines); } catch (Exception ex) { MessageBox.Show(ex.Message, MethodInfo.GetCurrentMethod().Name); return(null); } }
private void MyLocalSettings_PublicSettingsDirectoryChanged(object sender, EventArgs e) { myLocalSettings = App.InitLocalSettings(); //lese Lokale Einstellungen if (Path.GetPathRoot(myLocalSettings.PublicSettingsDirectory) != Path.GetPathRoot(Application.StartupPath)) //prüfe, ob Netzlaufwerk verwendet wird { if (System.IO.Directory.Exists(Path.GetPathRoot(myLocalSettings.PublicSettingsDirectory))) //prüfe, ob Pfad existiert { myMachines = App.InitMachines(myLocalSettings.PublicSettingsDirectory); } else { myMachines = App.InitMachines(Application.StartupPath); } } else { myMachines = App.InitMachines(myLocalSettings.PublicSettingsDirectory); } myLocalSettings.Machines = myMachines; myLocalSettings.DefaultMachineBackground = myMachines.ListOfMachines(); }
private void ReadOrInitSettings() { myLocalSettings = App.InitLocalSettings(); //lese Lokale Einstellungen toolStripStatusLabel1.Text = ""; //status Netzlaufwerk toolStripStatusLabel1.Image = null; toolStripStatusLabel1.BorderSides = ToolStripStatusLabelBorderSides.None; try { if (Path.GetPathRoot(myLocalSettings.PublicSettingsDirectory) != Path.GetPathRoot(Application.StartupPath)) //prüfe, ob Netzlaufwerk verwendet wird { if (Directory.Exists(Path.GetPathRoot(myLocalSettings.PublicSettingsDirectory))) //prüfe, ob Pfad / Netzlaufweerk existiert { myMachines = App.InitMachines(myLocalSettings.PublicSettingsDirectory); FileSystem.FileCopy(Path.Combine(myLocalSettings.PublicSettingsDirectory, LocalSettings.PublicSettingsFile), //Kopie der Maschinen lokal speichern, falls Netzlaufwerk später evtl. nicht verfügbar Path.Combine(Application.StartupPath + LocalSettings.PublicsSubFolder, LocalSettings.PublicSettingsFile)); FileSystem.FileCopy(Path.Combine(myLocalSettings.PublicSettingsDirectory, "tool_table.template"), Path.Combine(Application.StartupPath + LocalSettings.PublicsSubFolder, "tool_table.template")); toolStripStatusLabel1.Text = Path.GetPathRoot(myLocalSettings.PublicSettingsDirectory); toolStripStatusLabel1.Image = Properties.Resources.Network_16x; toolStripStatusLabel1.BorderSides = ToolStripStatusLabelBorderSides.Left; } else { myMachines = App.InitMachines(Application.StartupPath + LocalSettings.PublicsSubFolder); myNetworkDriveAvailable = false; toolStripStatusLabel1.Text = "'" + Path.GetPathRoot(myLocalSettings.PublicSettingsDirectory) + "' nicht verfügbar!"; toolStripStatusLabel1.ForeColor = Color.Red; toolStripStatusLabel1.Image = Properties.Resources.ConnectionOffline_16x; toolStripStatusLabel1.BorderSides = ToolStripStatusLabelBorderSides.Left; WriteHistory("Die öffentlichen Eintellungen (Maschinen) konnten nicht im Netzlaufwerk '" + Path.GetPathRoot(myLocalSettings.PublicSettingsDirectory) + "' geladen werden.", HistoryMessageType.Error, FontStyle.Bold, true, false); WriteHistory("Netzlaufwerk evtl. nicht verfügbar! Es wird das letzte lokale Backup verwendet.", HistoryMessageType.Error, FontStyle.Bold, false, true); WriteHistory("Ohne Zugriff auf Netzlaufwerk '" + Path.GetPathRoot(myLocalSettings.PublicSettingsDirectory) + "' kann die 'Maschinen-Projekt-Liste' nicht gepflegt werden.", HistoryMessageType.Error, FontStyle.Bold, true, true); MessageBox.Show("Die öffentlichen Eintellungen (Maschinen) konnten nicht im Netzlaufwerk '" + myLocalSettings.PublicSettingsDirectory + "' geladen werden.\n\nEs wird ein lokales Backup der Maschinen-Datei verwendet.", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { myMachines = App.InitMachines(myLocalSettings.PublicSettingsDirectory); } foreach (Machine _Machine in myMachines) { if (_Machine.Name == myLocalSettings.DefaultMachine) { myMachine = _Machine; return; } } WriteHistory("Standardmaschine '" + myLocalSettings.DefaultMachine + "' konnte nicht geladen werden", HistoryMessageType.Error, FontStyle.Bold); myMachine = myMachines[0]; MessageBox.Show("Die Standardmaschine '" + myLocalSettings.DefaultMachine + "' konnte nicht geladen werden. Sie ist in den Einstellungen nicht definiert: \n\n" + System.IO.Path.Combine(myLocalSettings.PublicSettingsDirectory, LocalSettings.PublicSettingsFile) + "\n\nEs wurde die Maschine '" + myMachine.Name + "' geladen!", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { MessageBox.Show(ex.Message, MethodInfo.GetCurrentMethod().Name); } }