private bool ExecuteFile(GCInterface gcInterface, DeviceFileType type, bool wait) { switch (type) { case DeviceFileType.StartScript: return(ServiceControl.SetServiceStatus(gcInterface.InterfaceName, AdapterStatus.Running)); case DeviceFileType.StopScript: return(ServiceControl.SetServiceStatus(gcInterface.InterfaceName, AdapterStatus.Stopped)); } // map type DeviceFileType t = type; if (type == DeviceFileType.InstallScript || type == DeviceFileType.UninstallScript) { t = DeviceFileType.ServiceAssembly; } // find script DeviceFile file = gcInterface.Directory.Files.FindFirstFile(t); if (file == null) { GCError.SetLastError("Cannot find file : " + t.ToString() + " in " + gcInterface.ToString()); return(false); } // find installer DeviceFile installer = gcInterface.Directory.Files.FindFirstFile(DeviceFileType.Installer); if (installer == null) { GCError.SetLastError("Cannot find installer in " + gcInterface.ToString()); return(false); } ProcessControl pc = new ProcessControl(); string exefilename = ConfigHelper.GetFullPath(gcInterface.FolderPath + "\\" + file.Location); string installfilename = ConfigHelper.GetFullPath(gcInterface.FolderPath + "\\" + installer.Location); switch (type) { case DeviceFileType.ConfigAssembly: return(ProcessControl.ExecuteAssemblyDirectly(exefilename, AdapterConfigArgument.InIMWizard)); case DeviceFileType.MonitorAssembly: return(ProcessControl.ExecuteAssemblyDirectly(exefilename, "")); case DeviceFileType.InstallScript: return(pc.ExecuteAssembly(installfilename, "\"" + exefilename + "\"", true)); case DeviceFileType.UninstallScript: return(pc.ExecuteAssembly(installfilename, "-u \"" + exefilename + "\"", true)); } return(false); }
private void comboBoxType_SelectedIndexChanged(object sender, EventArgs e) { string strType = this.comboBoxType.Text; if (strType == null || strType.Length < 1) { return; } DeviceFileType type = (DeviceFileType)Enum.Parse(typeof(DeviceFileType), this.comboBoxType.Text); DeviceFile file = _dirMgt.DeviceDirInfor.Files.FindFirstFile(type); string filename = null; if (file != null) { filename = ConfigHelper.GetFullPath(file.Location); if (!File.Exists(filename)) { filename = null; } } if (filename == null) { if (MessageBox.Show(this, "Cannot find " + type.ToString() + ". Do you want to create one?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { string fn = type.ToString() + ".bat"; string fname = ConfigHelper.GetFullPath(fn); using (StreamWriter sw = File.CreateText(fname)) { sw.WriteLine("REM " + type.ToString()); } if (file == null) { file = new DeviceFile(); file.Backupable = true; file.Location = fn; file.Type = type; _dirMgt.DeviceDirInfor.Files.Add(file); if (!_dirMgt.SaveDeviceDir()) { MessageBox.Show("Save DeviceDir file failed."); return; } } } } this.textBoxScript.Tag = file; buttonLoad_Click(sender, e); }
public DeviceFile FindFirstFile(DeviceFileType type) { foreach (DeviceFile f in this) { if (f.Type == type) { return(f); } } return(null); }
public DeviceFile[] FindFiles(DeviceFileType type) { List <DeviceFile> list = new List <DeviceFile>(); foreach (DeviceFile f in this) { if (f.Type == type) { list.Add(f); } } return(list.ToArray()); }
public DeviceFile(DeviceFileType type, string filename) : this(type, filename, false) { }
public DeviceFile(DeviceFileType type, string filename, bool needBackup) { _type = type; _location = filename; _needBackup = needBackup; }
private static bool UpdateInterfaceScript(Hashtable paramTable, DeviceDir directory, DeviceFileType type, bool essentialFile) { DeviceFile[] files = directory.Files.FindFiles(type); if (files == null || files.Length < 1) { if (essentialFile) { GCError.SetLastError("Cannot find script file of type: " + type.ToString()); return(false); } else { return(true); } } foreach (DeviceFile file in files) { if (!UpdateInterfaceScript(paramTable, file, type, essentialFile)) { return(false); } } return(true); }
private static bool UpdateInterfaceScript(Hashtable paramTable, DeviceFile file, DeviceFileType type, bool essentialFile) { if (file == null) { if (essentialFile) { GCError.SetLastError("Cannot find script file of type: " + type.ToString()); return(false); } else { return(true); } } string path = paramTable[IMParameter.InterfaceDirectory] as string; string filename = path + "\\" + file.Location; try { string str = ""; using (StreamReader sr = File.OpenText(filename)) { str = sr.ReadToEnd(); } foreach (DictionaryEntry de in paramTable) { string key = de.Key as string; string value = de.Value as string; str = str.Replace(key, value); } using (StreamWriter sw = File.CreateText(filename)) { sw.Write(str); } return(true); } catch (Exception err) { GCError.SetLastError("Error when processing file: " + filename); GCError.SetLastError(err); return(false); } }