Sicherung
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
using FSI.Lib;
|
||||
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
|
||||
@@ -13,53 +16,52 @@ namespace FSI.BT.Tools.Commands
|
||||
{
|
||||
public override void Execute(object parameter)
|
||||
{
|
||||
string[] files = new string[] { };
|
||||
string[] pathes = new string[] { };
|
||||
string arguments = string.Empty;
|
||||
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.Settings.SieSimaticManagerExe;
|
||||
files = Global.AppSettings.Apps.SieSimaticManager;
|
||||
break;
|
||||
|
||||
case "TIAv13":
|
||||
files = Global.Settings.SieTiaV13Exe;
|
||||
files = Global.AppSettings.Apps.SieTiaV13;
|
||||
break;
|
||||
|
||||
case "TIAv14":
|
||||
files = Global.Settings.SieTiaV14Exe;
|
||||
files = Global.AppSettings.Apps.SieTiaV14;
|
||||
break;
|
||||
|
||||
case "TIAv15":
|
||||
files = Global.Settings.SieTiaV15Exe;
|
||||
files = Global.AppSettings.Apps.SieTiaV15;
|
||||
break;
|
||||
|
||||
case "TIAv16":
|
||||
files = Global.Settings.SieTiaV16Exe;
|
||||
files = Global.AppSettings.Apps.SieTiaV16;
|
||||
break;
|
||||
|
||||
case "TIAv17":
|
||||
files = Global.Settings.SieTiaV17Exe;
|
||||
files = Global.AppSettings.Apps.SieTiaV17;
|
||||
break;
|
||||
|
||||
case "Starter":
|
||||
files = Global.Settings.SieTiaVStarterExe;
|
||||
files = Global.AppSettings.Apps.SieTiaVStarter;
|
||||
break;
|
||||
|
||||
case "Epl":
|
||||
files = Global.Settings.EplExe;
|
||||
arguments = Global.Settings.EplArguments;
|
||||
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 = Global.Settings.EplPrjPath,
|
||||
EplExes = Global.Settings.EplExe,
|
||||
Path = FSI.BT.Tools.Settings.AppSettings.GetFolderByName(Global.AppSettings.Folders, "EplPrj").path,
|
||||
EplExe = selectedFile.ExePath,
|
||||
};
|
||||
frmMainEplPrj.Show();
|
||||
return;
|
||||
@@ -70,7 +72,7 @@ namespace FSI.BT.Tools.Commands
|
||||
ShowPdf = true,
|
||||
CloseAtLostFocus = true,
|
||||
WindowStartupLocation = WindowStartupLocation.CenterScreen,
|
||||
Path = Global.Settings.EplPdfPath,
|
||||
Path = FSI.BT.Tools.Settings.AppSettings.GetFolderByName(Global.AppSettings.Folders, "EplPdf").path
|
||||
};
|
||||
frmMainEplPdf.Show();
|
||||
return;
|
||||
@@ -84,29 +86,28 @@ namespace FSI.BT.Tools.Commands
|
||||
return;
|
||||
|
||||
case "Npp":
|
||||
files = Global.Settings.NppExe;
|
||||
files = Global.AppSettings.Apps.Npp;
|
||||
break;
|
||||
|
||||
case "TotalCmd":
|
||||
files = Global.Settings.TotalCmdExe;
|
||||
files = Global.AppSettings.Apps.TotalCmd;
|
||||
break;
|
||||
|
||||
case "TeXstudio":
|
||||
files = Global.Settings.TeXstudioExe;
|
||||
pathes = Global.Settings.TeXstudioPath;
|
||||
files = Global.AppSettings.Apps.TeXstudio;
|
||||
break;
|
||||
|
||||
case "VS":
|
||||
files = Global.Settings.VsExe;
|
||||
files = Global.AppSettings.Apps.Vs;
|
||||
break;
|
||||
|
||||
case "VS.Code":
|
||||
files = Global.Settings.VsCodeExe;
|
||||
files = Global.AppSettings.Apps.VsCode;
|
||||
break;
|
||||
|
||||
|
||||
case "Rdp":
|
||||
files = Global.Settings.RdpExe;
|
||||
files = Global.AppSettings.Apps.Rdp;
|
||||
break;
|
||||
|
||||
case "DeEncrypt":
|
||||
@@ -139,84 +140,80 @@ namespace FSI.BT.Tools.Commands
|
||||
}
|
||||
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 = false,
|
||||
// Data = Global.AppSettings.TxtToClip
|
||||
// };
|
||||
// frmTxtToClipMain.Show();
|
||||
// return;
|
||||
|
||||
case "Outlook":
|
||||
files = Global.Settings.OutlookExe;
|
||||
files = Global.AppSettings.Apps.Outlook;
|
||||
break;
|
||||
|
||||
case "Teams":
|
||||
files = Global.Settings.TeamsExe;
|
||||
arguments = Global.Settings.TeamsArg;
|
||||
files = Global.AppSettings.Apps.Teams;
|
||||
break;
|
||||
|
||||
case "Excel":
|
||||
files = Global.Settings.ExcelExe;
|
||||
files = Global.AppSettings.Apps.Excel;
|
||||
break;
|
||||
|
||||
case "Word":
|
||||
files = Global.Settings.WordExe;
|
||||
files = Global.AppSettings.Apps.Word;
|
||||
break;
|
||||
|
||||
case "PaintNet":
|
||||
files = Global.Settings.PaintNetExe;
|
||||
files = Global.AppSettings.Apps.PaintNet;
|
||||
break;
|
||||
|
||||
case "Gimp":
|
||||
files = Global.Settings.GimpExe;
|
||||
files = Global.AppSettings.Apps.Gimp;
|
||||
break;
|
||||
|
||||
case "Vnc":
|
||||
files = Global.Settings.VncExe;
|
||||
files = Global.AppSettings.Apps.Vnc;
|
||||
break;
|
||||
|
||||
case "VncAdrBook":
|
||||
files = Global.Settings.VncAdrBookExe;
|
||||
files = Global.AppSettings.Apps.VncAdrBook;
|
||||
break;
|
||||
|
||||
case "IbaAnalyzer":
|
||||
files = Global.Settings.VncAdrBookExe;
|
||||
files = Global.AppSettings.Apps.IbaAnalyzer;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
string fileName = string.Empty;
|
||||
string path = string.Empty;
|
||||
selectedFile = GetApp(files);
|
||||
|
||||
for (int i = 0; i <= files.Length - 1; i++)
|
||||
if (ProgramIsRunning(selectedFile.ExePath))
|
||||
{
|
||||
var test = Environment.ExpandEnvironmentVariables(files[i].Trim());
|
||||
if (File.Exists(Environment.ExpandEnvironmentVariables(files[i].Trim())))
|
||||
{
|
||||
fileName = Environment.ExpandEnvironmentVariables(files[i].Trim());
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pathes.Length == 0)
|
||||
{
|
||||
path = Path.GetDirectoryName(fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
path = Environment.ExpandEnvironmentVariables(pathes[i].Trim());
|
||||
}
|
||||
}
|
||||
|
||||
if (ProgramIsRunning(fileName))
|
||||
{
|
||||
ProgramToFront(fileName);
|
||||
ProgramToFront(selectedFile.ExePath);
|
||||
Global.Log.Info("Anwendung \"{0}\" wurde in den Vordergrund gebracht", selectedFile.ExePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
Process process = new Process();
|
||||
process.StartInfo.FileName = fileName;
|
||||
process.StartInfo.WorkingDirectory = path;
|
||||
process.StartInfo.Arguments = arguments;
|
||||
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)
|
||||
{
|
||||
@@ -225,47 +222,51 @@ namespace FSI.BT.Tools.Commands
|
||||
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);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanExecute(object parameter)
|
||||
{
|
||||
string[] files = new string[] { };
|
||||
IEnumerable<Settings.Exe.IExe> files = new List<Settings.Exe.IExe>();
|
||||
switch ((string)parameter)
|
||||
{
|
||||
case "SimaticManager":
|
||||
files = Global.Settings.SieSimaticManagerExe;
|
||||
files = Global.AppSettings.Apps.SieSimaticManager;
|
||||
break;
|
||||
|
||||
case "TIAv13":
|
||||
files = Global.Settings.SieTiaV13Exe;
|
||||
files = Global.AppSettings.Apps.SieTiaV13;
|
||||
break;
|
||||
|
||||
case "TIAv14":
|
||||
files = Global.Settings.SieTiaV14Exe;
|
||||
files = Global.AppSettings.Apps.SieTiaV14;
|
||||
break;
|
||||
|
||||
case "TIAv15":
|
||||
files = Global.Settings.SieTiaV13Exe;
|
||||
files = Global.AppSettings.Apps.SieTiaV15;
|
||||
break;
|
||||
|
||||
case "TIAv16":
|
||||
files = Global.Settings.SieTiaV16Exe;
|
||||
files = Global.AppSettings.Apps.SieTiaV16;
|
||||
break;
|
||||
|
||||
case "TIAv17":
|
||||
files = Global.Settings.SieTiaV17Exe;
|
||||
files = Global.AppSettings.Apps.SieTiaV17;
|
||||
break;
|
||||
|
||||
case "Starter":
|
||||
files = Global.Settings.SieTiaVStarterExe;
|
||||
files = Global.AppSettings.Apps.SieTiaVStarter;
|
||||
break;
|
||||
|
||||
case "Epl":
|
||||
files = Global.Settings.EplExe;
|
||||
files = Global.AppSettings.Apps.Epl;
|
||||
break;
|
||||
|
||||
case "EplPrj":
|
||||
@@ -278,28 +279,27 @@ namespace FSI.BT.Tools.Commands
|
||||
return Global.AdminRights;
|
||||
|
||||
case "Npp":
|
||||
files = Global.Settings.NppExe;
|
||||
files = Global.AppSettings.Apps.Npp;
|
||||
break;
|
||||
|
||||
case "TotalCmd":
|
||||
files = Global.Settings.TotalCmdExe;
|
||||
files = Global.AppSettings.Apps.TotalCmd;
|
||||
break;
|
||||
|
||||
case "TeXstudio":
|
||||
files = Global.Settings.TeXstudioExe;
|
||||
files = Global.AppSettings.Apps.TeXstudio;
|
||||
break;
|
||||
|
||||
case "VS":
|
||||
files = Global.Settings.VsExe;
|
||||
files = Global.AppSettings.Apps.Vs;
|
||||
break;
|
||||
|
||||
case "VS.Code":
|
||||
files = Global.Settings.VsCodeExe;
|
||||
files = Global.AppSettings.Apps.VsCode;
|
||||
break;
|
||||
|
||||
|
||||
case "Rdp":
|
||||
files = Global.Settings.RdpExe;
|
||||
files = Global.AppSettings.Apps.Rdp;
|
||||
break;
|
||||
|
||||
case "DeEncrypt":
|
||||
@@ -311,49 +311,55 @@ namespace FSI.BT.Tools.Commands
|
||||
case "Admin":
|
||||
return Global.SuperAdminRights;
|
||||
|
||||
case "Folder":
|
||||
return Global.AppSettings.Folders != null;
|
||||
|
||||
//case "TxtToClip":
|
||||
// return Global.AppSettings.TxtToClip != null;
|
||||
|
||||
case "Outlook":
|
||||
files = Global.Settings.OutlookExe;
|
||||
files = Global.AppSettings.Apps.Outlook;
|
||||
break;
|
||||
|
||||
case "Teams":
|
||||
files = Global.Settings.TeamsExe;
|
||||
files = Global.AppSettings.Apps.Teams;
|
||||
break;
|
||||
|
||||
case "Excel":
|
||||
files = Global.Settings.ExcelExe;
|
||||
files = Global.AppSettings.Apps.Excel;
|
||||
break;
|
||||
|
||||
case "Word":
|
||||
files = Global.Settings.WordExe;
|
||||
files = Global.AppSettings.Apps.Word;
|
||||
break;
|
||||
|
||||
case "PaintNet":
|
||||
files = Global.Settings.PaintNetExe;
|
||||
files = Global.AppSettings.Apps.PaintNet;
|
||||
break;
|
||||
|
||||
case "Gimp":
|
||||
files = Global.Settings.GimpExe;
|
||||
files = Global.AppSettings.Apps.Gimp;
|
||||
break;
|
||||
|
||||
case "Vnc":
|
||||
files = Global.Settings.VncExe;
|
||||
files = Global.AppSettings.Apps.Vnc;
|
||||
break;
|
||||
|
||||
case "VncAdrBook":
|
||||
files = Global.Settings.VncAdrBookExe;
|
||||
files = Global.AppSettings.Apps.VncAdrBook;
|
||||
break;
|
||||
|
||||
case "IbaAnalyzer":
|
||||
files = Global.Settings.VncAdrBookExe;
|
||||
files = Global.AppSettings.Apps.IbaAnalyzer;
|
||||
break;
|
||||
|
||||
default: return false;
|
||||
|
||||
}
|
||||
|
||||
foreach (string file in files)
|
||||
foreach (var file in files)
|
||||
{
|
||||
if (File.Exists(Environment.ExpandEnvironmentVariables(file.Trim())))
|
||||
if (File.Exists(Environment.ExpandEnvironmentVariables(file.ExePath.Trim())))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -382,6 +388,36 @@ namespace FSI.BT.Tools.Commands
|
||||
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")]
|
||||
|
||||
Reference in New Issue
Block a user