Sicherung
This commit is contained in:
308
FSI.BT.Tools/Commands/CmdCommand.cs
Normal file
308
FSI.BT.Tools/Commands/CmdCommand.cs
Normal file
@@ -0,0 +1,308 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
using static FSI.BT.Tools.Settings.Cmd;
|
||||
using static FSI.BT.Tools.Settings.Exe;
|
||||
|
||||
namespace FSI.BT.Tools.Commands
|
||||
{
|
||||
/// <summary>
|
||||
/// Shows the main window.
|
||||
/// </summary>
|
||||
public class CmdCommand : CommandBase<CmdCommand>
|
||||
{
|
||||
public override void Execute(object parameter)
|
||||
{
|
||||
if (parameter is not string)
|
||||
{
|
||||
Global.Log.Error("Parameter ist kein String");
|
||||
return;
|
||||
}
|
||||
|
||||
var cmds = Global.AppSettings.Cmds.ToList();
|
||||
ICmd selectedCmd = null;
|
||||
|
||||
// IEnumerable<Settings.Exe.IExe> files = new List<Settings.Exe.IExe>();
|
||||
IExe selectedFile;
|
||||
|
||||
switch ((string)parameter)
|
||||
{
|
||||
|
||||
case "EplPrj":
|
||||
//selectedFile = GetApp(Global.AppSettings.Apps.Epl);
|
||||
//Lib.Guis.Prj.Mgt.FrmMain frmMainEplPrj = new()
|
||||
//{
|
||||
// ShowPdf = false,
|
||||
// CloseAtLostFocus = true,
|
||||
// WindowStartupLocation = WindowStartupLocation.CenterScreen,
|
||||
// Path = FSI.BT.Tools.Settings.AppSettings.GetFolderByName(Global.AppSettings.Folders, "EplPrj").path,
|
||||
// EplExe = selectedFile.ExePath,
|
||||
//};
|
||||
//frmMainEplPrj.Show();
|
||||
return;
|
||||
|
||||
case "EplPdf":
|
||||
Lib.Guis.Prj.Mgt.FrmMain frmMainEplPdf = new()
|
||||
{
|
||||
ShowPdf = true,
|
||||
CloseAtLostFocus = true,
|
||||
WindowStartupLocation = WindowStartupLocation.CenterScreen,
|
||||
Path = FSI.BT.Tools.Settings.AppSettings.GetFolderByName(Global.AppSettings.Folders, "EplPdf").path
|
||||
};
|
||||
frmMainEplPdf.Show();
|
||||
return;
|
||||
|
||||
case "EplPdfMgt":
|
||||
Lib.Guis.Pdf.Mgt.FrmMain frmMainEplPdfMgt = new()
|
||||
{
|
||||
CloseAtLostFocus = true
|
||||
};
|
||||
frmMainEplPdfMgt.Show();
|
||||
return;
|
||||
|
||||
case "DeEncrypt":
|
||||
Lib.Guis.DeEncryptMessage.FrmMain frmMainDeEnCrypt = new()
|
||||
{
|
||||
Password = AppDomain.CurrentDomain.FriendlyName,
|
||||
CloseAtLostFocus = true,
|
||||
WindowStartupLocation = WindowStartupLocation.CenterScreen,
|
||||
};
|
||||
frmMainDeEnCrypt.Show();
|
||||
return;
|
||||
|
||||
case "StarterCsvExporter":
|
||||
Lib.Guis.SieStarterCsvExporter.FrmMain frmMain = new();
|
||||
frmMain.Show();
|
||||
return;
|
||||
|
||||
case "Folder":
|
||||
Lib.Guis.Folder.Mgt.FrmMain frmFolderMgtMain = new()
|
||||
{
|
||||
CloseAtLostFocus = true,
|
||||
Data = Global.AppSettings.Folders
|
||||
};
|
||||
frmFolderMgtMain.Show();
|
||||
return;
|
||||
|
||||
case "TxtToClip":
|
||||
Lib.Guis.TxtToClip.Mgt.FrmMain frmTxtToClipMain = new()
|
||||
{
|
||||
CloseAtLostFocus = true,
|
||||
InputData = Global.AppSettings.TxtToClip
|
||||
};
|
||||
frmTxtToClipMain.Show();
|
||||
return;
|
||||
|
||||
default:
|
||||
foreach (ICmd cmd in cmds)
|
||||
{
|
||||
if (String.Equals(parameter.ToString().ToLower(), cmd.Cmd.ToLower()))
|
||||
{
|
||||
selectedCmd = cmd;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (selectedCmd == null)
|
||||
return;
|
||||
|
||||
OpenExe(selectedCmd);
|
||||
OpenUrl(selectedCmd);
|
||||
}
|
||||
|
||||
public override bool CanExecute(object parameter)
|
||||
{
|
||||
var cmds = Global.AppSettings.Cmds.ToList();
|
||||
ICmd selectedCmd = null;
|
||||
|
||||
switch ((string)parameter)
|
||||
{
|
||||
case "EplPrj":
|
||||
return true;
|
||||
|
||||
case "EplPdf":
|
||||
return true;
|
||||
|
||||
case "EplPdfMgt":
|
||||
return Global.AdminRights;
|
||||
|
||||
case "DeEncrypt":
|
||||
return Global.AdminRights;
|
||||
|
||||
case "StarterCsvExporter":
|
||||
return Global.AdminRights;
|
||||
|
||||
case "Folder":
|
||||
return Global.AppSettings.Folders != null;
|
||||
|
||||
case "TxtToClip":
|
||||
return Global.AppSettings.TxtToClip != null;
|
||||
|
||||
default:
|
||||
foreach (ICmd cmd in cmds)
|
||||
{
|
||||
if (String.Equals(parameter.ToString().ToLower(), cmd.Cmd.ToLower()))
|
||||
{
|
||||
selectedCmd = cmd;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (selectedCmd == null)
|
||||
return false;
|
||||
|
||||
foreach (var file in selectedCmd.Exe.ToList())
|
||||
{
|
||||
if (File.Exists(Environment.ExpandEnvironmentVariables(file.ExePath.Trim())))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var url in selectedCmd.Urls)
|
||||
{
|
||||
if (url != String.Empty)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private static void OpenExe(ICmd selectedCmd)
|
||||
{
|
||||
IExe selectedFile = GetApp(selectedCmd.Exe);
|
||||
|
||||
if (selectedFile == null)
|
||||
return;
|
||||
|
||||
if (selectedFile.ExePath == String.Empty)
|
||||
return;
|
||||
|
||||
if (ProgramIsRunning(selectedFile.ExePath))
|
||||
{
|
||||
ProgramToFront(selectedFile.ExePath);
|
||||
Global.Log.Info("Anwendung \"{0}\" wurde in den Vordergrund gebracht", selectedFile.ExePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
Process process = new();
|
||||
process.StartInfo.FileName = selectedFile.ExePath;
|
||||
process.StartInfo.WorkingDirectory = selectedFile.Path == null ? selectedFile.Path : Path.GetDirectoryName(selectedFile.ExePath);
|
||||
process.StartInfo.Arguments = selectedFile.Arguments;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
process.Start();
|
||||
Global.Log.Info("Anwendung \"{0}\" wurde gestartet", selectedFile.ExePath);
|
||||
}
|
||||
catch (System.ComponentModel.Win32Exception ex) when (ex.NativeErrorCode == 740)
|
||||
{
|
||||
try
|
||||
{
|
||||
process.StartInfo.UseShellExecute = true;
|
||||
process.StartInfo.Verb = "runas";
|
||||
process.Start();
|
||||
Global.Log.Info("Anwendung \"{0}\" wurde als Admin gestartet", selectedFile.ExePath);
|
||||
}
|
||||
catch (Exception ex2)
|
||||
{
|
||||
Global.Log.Info("Anwendung konnte durch folgenden Fehler \"{0}\" nicht gestartet werden.", ex2.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void OpenUrl(ICmd selectedCmd)
|
||||
{
|
||||
|
||||
foreach (var url in selectedCmd.Urls)
|
||||
{
|
||||
|
||||
if (url == String.Empty)
|
||||
return;
|
||||
|
||||
Process.Start(new ProcessStartInfo(url.Replace("&", "^&")) { UseShellExecute = true });
|
||||
Global.Log.Info("Link \"{0}\" wurde geföffnet.", url.Replace("&", "^&"));
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool ProgramIsRunning(string FullPath)
|
||||
{
|
||||
string FilePath = Path.GetDirectoryName(FullPath);
|
||||
string FileName = Path.GetFileNameWithoutExtension(FullPath).ToLower();
|
||||
bool isRunning = false;
|
||||
|
||||
Process[] pList = Process.GetProcessesByName(FileName);
|
||||
|
||||
foreach (Process p in pList)
|
||||
{
|
||||
if (p.MainModule.FileName.StartsWith(FilePath, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
isRunning = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return isRunning;
|
||||
}
|
||||
|
||||
private static IExe GetApp(IEnumerable<IExe> files)
|
||||
{
|
||||
if(files.ToList().Count == 0)
|
||||
return null;
|
||||
|
||||
var selectedFile = files.ToList()[0];
|
||||
|
||||
foreach (var file in files.ToList())
|
||||
{
|
||||
if (File.Exists(Environment.ExpandEnvironmentVariables(file.ExePath.Trim())))
|
||||
selectedFile = (IExe)file;
|
||||
else
|
||||
continue;
|
||||
}
|
||||
|
||||
return selectedFile;
|
||||
}
|
||||
|
||||
[System.Runtime.InteropServices.DllImport("User32.dll")]
|
||||
private static extern bool SetForegroundWindow(IntPtr handle);
|
||||
[System.Runtime.InteropServices.DllImport("User32.dll")]
|
||||
private static extern bool ShowWindow(IntPtr handle, int nCmdShow);
|
||||
[System.Runtime.InteropServices.DllImport("User32.dll")]
|
||||
private static extern bool IsIconic(IntPtr handle);
|
||||
|
||||
private static void ProgramToFront(string FullPath)
|
||||
{
|
||||
string FilePath = Path.GetDirectoryName(FullPath);
|
||||
string FileName = Path.GetFileNameWithoutExtension(FullPath).ToLower();
|
||||
|
||||
Process[] pList = Process.GetProcessesByName(FileName);
|
||||
|
||||
foreach (Process p in pList)
|
||||
{
|
||||
if (p.MainModule.FileName.StartsWith(FilePath, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
IntPtr handle = p.MainWindowHandle;
|
||||
if (IsIconic(handle))
|
||||
{
|
||||
ShowWindow(handle, 9);
|
||||
}
|
||||
SetForegroundWindow(handle);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,449 +0,0 @@
|
||||
using FSI.BT.Tools.Settings;
|
||||
using FSI.Lib;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
|
||||
namespace FSI.BT.Tools.Commands
|
||||
{
|
||||
/// <summary>
|
||||
/// Shows the main window.
|
||||
/// </summary>
|
||||
public class OpenAppCommand : CommandBase<OpenAppCommand>
|
||||
{
|
||||
public override void Execute(object parameter)
|
||||
{
|
||||
IEnumerable<Settings.Exe.IExe> files = new List<Settings.Exe.IExe>();
|
||||
(string ExePath, string Path, string Arguments) selectedFile = (string.Empty, string.Empty, string.Empty);
|
||||
|
||||
switch ((string)parameter)
|
||||
{
|
||||
case "SimaticManager":
|
||||
files = Global.AppSettings.Apps.SieSimaticManager;
|
||||
break;
|
||||
|
||||
case "TIAv13":
|
||||
files = Global.AppSettings.Apps.SieTiaV13;
|
||||
break;
|
||||
|
||||
case "TIAv14":
|
||||
files = Global.AppSettings.Apps.SieTiaV14;
|
||||
break;
|
||||
|
||||
case "TIAv15":
|
||||
files = Global.AppSettings.Apps.SieTiaV15;
|
||||
break;
|
||||
|
||||
case "TIAv16":
|
||||
files = Global.AppSettings.Apps.SieTiaV16;
|
||||
break;
|
||||
|
||||
case "TIAv17":
|
||||
files = Global.AppSettings.Apps.SieTiaV17;
|
||||
break;
|
||||
|
||||
case "Starter":
|
||||
files = Global.AppSettings.Apps.SieTiaVStarter;
|
||||
break;
|
||||
|
||||
case "Epl":
|
||||
files = Global.AppSettings.Apps.Epl;
|
||||
break;
|
||||
|
||||
case "EplPrj":
|
||||
selectedFile = GetApp(Global.AppSettings.Apps.Epl);
|
||||
Lib.Guis.Prj.Mgt.FrmMain frmMainEplPrj = new Lib.Guis.Prj.Mgt.FrmMain()
|
||||
{
|
||||
ShowPdf = false,
|
||||
CloseAtLostFocus = true,
|
||||
WindowStartupLocation = WindowStartupLocation.CenterScreen,
|
||||
Path = FSI.BT.Tools.Settings.AppSettings.GetFolderByName(Global.AppSettings.Folders, "EplPrj").path,
|
||||
EplExe = selectedFile.ExePath,
|
||||
};
|
||||
frmMainEplPrj.Show();
|
||||
return;
|
||||
|
||||
case "EplPdf":
|
||||
Lib.Guis.Prj.Mgt.FrmMain frmMainEplPdf = new Lib.Guis.Prj.Mgt.FrmMain()
|
||||
{
|
||||
ShowPdf = true,
|
||||
CloseAtLostFocus = true,
|
||||
WindowStartupLocation = WindowStartupLocation.CenterScreen,
|
||||
Path = FSI.BT.Tools.Settings.AppSettings.GetFolderByName(Global.AppSettings.Folders, "EplPdf").path
|
||||
};
|
||||
frmMainEplPdf.Show();
|
||||
return;
|
||||
|
||||
case "EplPdfMgt":
|
||||
Lib.Guis.Pdf.Mgt.FrmMain frmMainEplPdfMgt = new Lib.Guis.Pdf.Mgt.FrmMain()
|
||||
{
|
||||
CloseAtLostFocus = true
|
||||
};
|
||||
frmMainEplPdfMgt.Show();
|
||||
return;
|
||||
|
||||
case "Npp":
|
||||
files = Global.AppSettings.Apps.Npp;
|
||||
break;
|
||||
|
||||
case "TotalCmd":
|
||||
files = Global.AppSettings.Apps.TotalCmd;
|
||||
break;
|
||||
|
||||
case "TeXstudio":
|
||||
files = Global.AppSettings.Apps.TeXstudio;
|
||||
break;
|
||||
|
||||
case "VS":
|
||||
files = Global.AppSettings.Apps.Vs;
|
||||
break;
|
||||
|
||||
case "VS.Code":
|
||||
files = Global.AppSettings.Apps.VsCode;
|
||||
break;
|
||||
|
||||
case "Rdp":
|
||||
files = Global.AppSettings.Apps.Rdp;
|
||||
break;
|
||||
|
||||
case "DeEncrypt":
|
||||
Lib.Guis.DeEncryptMessage.FrmMain frmMainDeEnCrypt = new Lib.Guis.DeEncryptMessage.FrmMain()
|
||||
{
|
||||
Password = GetType().Namespace.ToString(),
|
||||
CloseAtLostFocus = true,
|
||||
WindowStartupLocation = WindowStartupLocation.CenterScreen,
|
||||
};
|
||||
frmMainDeEnCrypt.Show();
|
||||
return;
|
||||
|
||||
case "StarterCsvExporter":
|
||||
Lib.Guis.SieStarterCsvExporter.FrmMain frmMain = new Lib.Guis.SieStarterCsvExporter.FrmMain();
|
||||
frmMain.Show();
|
||||
return;
|
||||
|
||||
case "Admin":
|
||||
Gui.FrmAdmin frmAdmin = new Gui.FrmAdmin()
|
||||
{
|
||||
Admins = Global.Settings.Admins,
|
||||
Users = Global.Settings.Users,
|
||||
};
|
||||
frmAdmin.ShowDialog();
|
||||
|
||||
if (frmAdmin.DialogResult.HasValue && frmAdmin.DialogResult.Value)
|
||||
{
|
||||
Global.Settings.Admins = frmAdmin.Admins;
|
||||
Global.Settings.Users = frmAdmin.Users;
|
||||
}
|
||||
return;
|
||||
|
||||
case "Folder":
|
||||
Lib.Guis.Folder.Mgt.FrmMain frmFolderMgtMain = new Lib.Guis.Folder.Mgt.FrmMain()
|
||||
{
|
||||
CloseAtLostFocus = true,
|
||||
Data = Global.AppSettings.Folders
|
||||
};
|
||||
frmFolderMgtMain.Show();
|
||||
return;
|
||||
|
||||
case "TxtToClip":
|
||||
Lib.Guis.TxtToClip.Mgt.FrmMain frmTxtToClipMain = new Lib.Guis.TxtToClip.Mgt.FrmMain()
|
||||
{
|
||||
CloseAtLostFocus = true,
|
||||
InputData = Global.AppSettings.TxtToClip
|
||||
};
|
||||
frmTxtToClipMain.Show();
|
||||
return;
|
||||
|
||||
case "Outlook":
|
||||
files = Global.AppSettings.Apps.Outlook;
|
||||
break;
|
||||
|
||||
case "Teams":
|
||||
files = Global.AppSettings.Apps.Teams;
|
||||
break;
|
||||
|
||||
case "Excel":
|
||||
files = Global.AppSettings.Apps.Excel;
|
||||
break;
|
||||
|
||||
case "Word":
|
||||
files = Global.AppSettings.Apps.Word;
|
||||
break;
|
||||
|
||||
case "PaintNet":
|
||||
files = Global.AppSettings.Apps.PaintNet;
|
||||
break;
|
||||
|
||||
case "Gimp":
|
||||
files = Global.AppSettings.Apps.Gimp;
|
||||
break;
|
||||
|
||||
case "Vnc":
|
||||
files = Global.AppSettings.Apps.Vnc;
|
||||
break;
|
||||
|
||||
case "VncAdrBook":
|
||||
files = Global.AppSettings.Apps.VncAdrBook;
|
||||
break;
|
||||
|
||||
case "IbaAnalyzer":
|
||||
files = Global.AppSettings.Apps.IbaAnalyzer;
|
||||
break;
|
||||
}
|
||||
|
||||
selectedFile = GetApp(files);
|
||||
|
||||
if (ProgramIsRunning(selectedFile.ExePath))
|
||||
{
|
||||
ProgramToFront(selectedFile.ExePath);
|
||||
Global.Log.Info("Anwendung \"{0}\" wurde in den Vordergrund gebracht", selectedFile.ExePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
Process process = new Process();
|
||||
process.StartInfo.FileName = selectedFile.ExePath;
|
||||
process.StartInfo.WorkingDirectory = selectedFile.Path;
|
||||
process.StartInfo.Arguments = selectedFile.Arguments;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
process.Start();
|
||||
Global.Log.Info("Anwendung \"{0}\" wurde gestartet", selectedFile.ExePath);
|
||||
}
|
||||
catch (System.ComponentModel.Win32Exception ex) when (ex.NativeErrorCode == 740)
|
||||
{
|
||||
try
|
||||
{
|
||||
process.StartInfo.UseShellExecute = true;
|
||||
process.StartInfo.Verb = "runas";
|
||||
process.Start();
|
||||
Global.Log.Info("Anwendung \"{0}\" wurde als Admin gestartet", selectedFile.ExePath);
|
||||
}
|
||||
catch (Exception ex2)
|
||||
{
|
||||
Global.Log.Info("Anwendung konnte durch folgenden Fehler \"{0}\" nicht gestartet werden.", ex2.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanExecute(object parameter)
|
||||
{
|
||||
IEnumerable<Settings.Exe.IExe> files = new List<Settings.Exe.IExe>();
|
||||
switch ((string)parameter)
|
||||
{
|
||||
case "SimaticManager":
|
||||
files = Global.AppSettings.Apps.SieSimaticManager;
|
||||
break;
|
||||
|
||||
case "TIAv13":
|
||||
files = Global.AppSettings.Apps.SieTiaV13;
|
||||
break;
|
||||
|
||||
case "TIAv14":
|
||||
files = Global.AppSettings.Apps.SieTiaV14;
|
||||
break;
|
||||
|
||||
case "TIAv15":
|
||||
files = Global.AppSettings.Apps.SieTiaV15;
|
||||
break;
|
||||
|
||||
case "TIAv16":
|
||||
files = Global.AppSettings.Apps.SieTiaV16;
|
||||
break;
|
||||
|
||||
case "TIAv17":
|
||||
files = Global.AppSettings.Apps.SieTiaV17;
|
||||
break;
|
||||
|
||||
case "Starter":
|
||||
files = Global.AppSettings.Apps.SieTiaVStarter;
|
||||
break;
|
||||
|
||||
case "Epl":
|
||||
files = Global.AppSettings.Apps.Epl;
|
||||
break;
|
||||
|
||||
case "EplPrj":
|
||||
return true;
|
||||
|
||||
case "EplPdf":
|
||||
return true;
|
||||
|
||||
case "EplPdfMgt":
|
||||
return Global.AdminRights;
|
||||
|
||||
case "Npp":
|
||||
files = Global.AppSettings.Apps.Npp;
|
||||
break;
|
||||
|
||||
case "TotalCmd":
|
||||
files = Global.AppSettings.Apps.TotalCmd;
|
||||
break;
|
||||
|
||||
case "TeXstudio":
|
||||
files = Global.AppSettings.Apps.TeXstudio;
|
||||
break;
|
||||
|
||||
case "VS":
|
||||
files = Global.AppSettings.Apps.Vs;
|
||||
break;
|
||||
|
||||
case "VS.Code":
|
||||
files = Global.AppSettings.Apps.VsCode;
|
||||
break;
|
||||
|
||||
case "Rdp":
|
||||
files = Global.AppSettings.Apps.Rdp;
|
||||
break;
|
||||
|
||||
case "DeEncrypt":
|
||||
return Global.AdminRights;
|
||||
|
||||
case "StarterCsvExporter":
|
||||
return Global.AdminRights;
|
||||
|
||||
case "Admin":
|
||||
return Global.SuperAdminRights;
|
||||
|
||||
case "Folder":
|
||||
return Global.AppSettings.Folders != null;
|
||||
|
||||
case "TxtToClip":
|
||||
return Global.AppSettings.TxtToClip != null;
|
||||
|
||||
case "Outlook":
|
||||
files = Global.AppSettings.Apps.Outlook;
|
||||
break;
|
||||
|
||||
case "Teams":
|
||||
files = Global.AppSettings.Apps.Teams;
|
||||
break;
|
||||
|
||||
case "Excel":
|
||||
files = Global.AppSettings.Apps.Excel;
|
||||
break;
|
||||
|
||||
case "Word":
|
||||
files = Global.AppSettings.Apps.Word;
|
||||
break;
|
||||
|
||||
case "PaintNet":
|
||||
files = Global.AppSettings.Apps.PaintNet;
|
||||
break;
|
||||
|
||||
case "Gimp":
|
||||
files = Global.AppSettings.Apps.Gimp;
|
||||
break;
|
||||
|
||||
case "Vnc":
|
||||
files = Global.AppSettings.Apps.Vnc;
|
||||
break;
|
||||
|
||||
case "VncAdrBook":
|
||||
files = Global.AppSettings.Apps.VncAdrBook;
|
||||
break;
|
||||
|
||||
case "IbaAnalyzer":
|
||||
files = Global.AppSettings.Apps.IbaAnalyzer;
|
||||
break;
|
||||
|
||||
default: return false;
|
||||
|
||||
}
|
||||
|
||||
foreach (var file in files)
|
||||
{
|
||||
if (File.Exists(Environment.ExpandEnvironmentVariables(file.ExePath.Trim())))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool ProgramIsRunning(string FullPath)
|
||||
{
|
||||
string FilePath = Path.GetDirectoryName(FullPath);
|
||||
string FileName = Path.GetFileNameWithoutExtension(FullPath).ToLower();
|
||||
bool isRunning = false;
|
||||
|
||||
Process[] pList = Process.GetProcessesByName(FileName);
|
||||
|
||||
foreach (Process p in pList)
|
||||
{
|
||||
if (p.MainModule.FileName.StartsWith(FilePath, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
isRunning = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return isRunning;
|
||||
}
|
||||
|
||||
private (string ExePath, string Path, string Arguments) GetApp(IEnumerable<Settings.Exe.IExe> files)
|
||||
{
|
||||
(string ExePath, string Path, string Arguments) selectedFile = (string.Empty, string.Empty, string.Empty);
|
||||
|
||||
for (int i = 0; i < files.ToList().Count; i++)
|
||||
{
|
||||
if (File.Exists(Environment.ExpandEnvironmentVariables(files.ToList()[i].ExePath.Trim())))
|
||||
{
|
||||
selectedFile.ExePath = Environment.ExpandEnvironmentVariables(files.ToList()[i].ExePath.Trim());
|
||||
selectedFile.Arguments = files.ToList()[i].Arguments;
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (selectedFile.Path == String.Empty)
|
||||
{
|
||||
selectedFile.Path = Path.GetDirectoryName(selectedFile.ExePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
selectedFile.Path = Path.GetDirectoryName(files.ToList()[i].ExePath.Trim());
|
||||
//selectedFile.Path = Environment.ExpandEnvironmentVariables(files.ToList()[i].ExePath.Trim());
|
||||
}
|
||||
}
|
||||
|
||||
return selectedFile;
|
||||
}
|
||||
|
||||
[System.Runtime.InteropServices.DllImport("User32.dll")]
|
||||
private static extern bool SetForegroundWindow(IntPtr handle);
|
||||
[System.Runtime.InteropServices.DllImport("User32.dll")]
|
||||
private static extern bool ShowWindow(IntPtr handle, int nCmdShow);
|
||||
[System.Runtime.InteropServices.DllImport("User32.dll")]
|
||||
private static extern bool IsIconic(IntPtr handle);
|
||||
|
||||
private void ProgramToFront(string FullPath)
|
||||
{
|
||||
string FilePath = Path.GetDirectoryName(FullPath);
|
||||
string FileName = Path.GetFileNameWithoutExtension(FullPath).ToLower();
|
||||
|
||||
Process[] pList = Process.GetProcessesByName(FileName);
|
||||
|
||||
foreach (Process p in pList)
|
||||
{
|
||||
if (p.MainModule.FileName.StartsWith(FilePath, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
IntPtr handle = p.MainWindowHandle;
|
||||
if (IsIconic(handle))
|
||||
{
|
||||
ShowWindow(handle, 9);
|
||||
}
|
||||
SetForegroundWindow(handle);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
using FSI.Lib;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace FSI.BT.Tools.Commands
|
||||
{
|
||||
/// <summary>
|
||||
/// Shows the main window.
|
||||
/// </summary>
|
||||
public class OpenLinkCommand : CommandBase<OpenLinkCommand>
|
||||
{
|
||||
public override void Execute(object parameter)
|
||||
{
|
||||
string url = String.Empty;
|
||||
|
||||
switch ((string)parameter)
|
||||
{
|
||||
case "ZentralWeb":
|
||||
url = Global.AppSettings.Urls.ZentralWeb;
|
||||
break;
|
||||
|
||||
case "Schichtbuch":
|
||||
url = Global.AppSettings.Urls.Schichtbuch;
|
||||
break;
|
||||
|
||||
case "SPS":
|
||||
url = Global.AppSettings.Urls.SPS;
|
||||
break;
|
||||
|
||||
case "PL1.Pls":
|
||||
url = Global.AppSettings.Urls.Pl1Pls;
|
||||
break;
|
||||
|
||||
case "PL2.Pls":
|
||||
url = Global.AppSettings.Urls.Pl2Pls;
|
||||
break;
|
||||
|
||||
case "PL2.Als":
|
||||
url = Global.AppSettings.Urls.Pl2Als;
|
||||
break;
|
||||
|
||||
case "PL3.Pls":
|
||||
url = Global.AppSettings.Urls.Pl3Pls;
|
||||
break;
|
||||
|
||||
case "FSI.Gitea":
|
||||
url = Global.AppSettings.Urls.Gitea;
|
||||
break;
|
||||
|
||||
case "FSI.Wiki":
|
||||
url = Global.AppSettings.Urls.Wiki;
|
||||
break;
|
||||
|
||||
case "Erp":
|
||||
url = Global.AppSettings.Urls.Erp;
|
||||
break;
|
||||
}
|
||||
|
||||
if (url == String.Empty)
|
||||
return;
|
||||
|
||||
url = url.Replace("&", "^&");
|
||||
Process.Start(new ProcessStartInfo(url) { UseShellExecute = true });
|
||||
Global.Log.Info("Link \"{0}\" wurde geföffnet.", url);
|
||||
}
|
||||
|
||||
public override bool CanExecute(object parameter)
|
||||
{
|
||||
string url = String.Empty;
|
||||
switch ((string)parameter)
|
||||
{
|
||||
case "FSI.Gitea":
|
||||
return Global.AdminRights;
|
||||
|
||||
case "FSI.Wiki":
|
||||
return Global.AdminRights;
|
||||
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,4 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace FSI.BT.Tools.Commands
|
||||
namespace FSI.BT.Tools.Commands
|
||||
{
|
||||
/// <summary>
|
||||
/// Shows the main window.
|
||||
@@ -10,32 +7,15 @@ namespace FSI.BT.Tools.Commands
|
||||
{
|
||||
public override void Execute(object parameter)
|
||||
{
|
||||
Gui.FrmProcesses frm = new Gui.FrmProcesses();
|
||||
frm.WinCC = Global.WinCC;
|
||||
Gui.FrmProcesses frm = new Gui.FrmProcesses()
|
||||
{
|
||||
WinCC = Global.WinCC
|
||||
};
|
||||
;
|
||||
frm.Iba = Global.Iba;
|
||||
Global.Window.Load();
|
||||
frm.WindowMgt = Global.WindowMgt;
|
||||
frm.Closed += Frm_Closed;
|
||||
frm.ShowDialog();
|
||||
}
|
||||
|
||||
private void Frm_Closed(object sender, System.EventArgs e)
|
||||
{
|
||||
Global.WinCC = ((Gui.FrmProcesses)sender).WinCC;
|
||||
|
||||
Global.Settings.SieTiaWinCCMsgMgtAutostart = Global.WinCC.WinCC.AutoStart;
|
||||
Global.Settings.SieTiaWinCCMsgMgtUpdateIntervall = Global.WinCC.WinCC.UpdateIntervall;
|
||||
Global.Settings.SieTiaWinCCMsgMgtWindowsName = Global.WinCC.WinCC.WindowsName;
|
||||
Global.Settings.SieTiaWinCCMsgMgtClassName = Global.WinCC.WinCC.WindowsClassName;
|
||||
Global.Settings.SieTiaWinCCMsgMgtBtnName = Global.WinCC.WinCC.ButtonName;
|
||||
|
||||
Global.Iba = ((Gui.FrmProcesses)sender).Iba;
|
||||
Global.Settings.IbaRecordDestinationath = Global.Iba.Iba.Destination;
|
||||
Global.Settings.IbaRecordSourcePath = Global.Iba.Iba.Source;
|
||||
Global.Settings.IbaAutoSync = Global.Iba.Iba.AutoStart;
|
||||
|
||||
Global.WindowMgt = ((Gui.FrmProcesses)sender).WindowMgt;
|
||||
Global.Window.Save();
|
||||
frm.ShowDialog();
|
||||
}
|
||||
|
||||
public override bool CanExecute(object parameter)
|
||||
|
||||
@@ -18,13 +18,9 @@ namespace FSI.BT.Tools.Commands
|
||||
}
|
||||
|
||||
if (Global.FrmRadialMenu.Visibility == Visibility.Hidden)
|
||||
{
|
||||
Global.FrmRadialMenu.Visibility = Visibility.Visible;
|
||||
}
|
||||
else
|
||||
{
|
||||
Global.FrmRadialMenu.Visibility = Visibility.Hidden;
|
||||
}
|
||||
Global.FrmRadialMenu.Visibility = Visibility.Hidden;
|
||||
|
||||
Global.FrmRadialMenu.ActivateCenteredToMouse();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user