Skip to content

Commit 2556077

Browse files
authored
Merge pull request #111 from minhe7735/add-openAny
Add `open_any` action + possible fix for PowerShell opening + implement new setting - due for testing
2 parents d3a5cb9 + bbe686f commit 2556077

File tree

16 files changed

+109
-18
lines changed

16 files changed

+109
-18
lines changed

AssistantComputerControl/Actions.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,37 @@ public void Open(string parameter) {
445445
}
446446
}
447447
}
448+
public void OpenAny(string parameter) {
449+
string fileLocation = MainProgram.shortcutLocation;
450+
Regex rx = new Regex("^" + parameter + Regex.Escape(".") + ".*", RegexOptions.IgnoreCase);
451+
452+
if (Directory.Exists(fileLocation) || Uri.IsWellFormedUriString(fileLocation, UriKind.Absolute)) {
453+
DirectoryInfo d = new DirectoryInfo(fileLocation);
454+
bool opened = false;
455+
foreach (var dirFile in d.GetFiles()) {
456+
if (!MainProgram.testingAction) {
457+
bool result = rx.IsMatch(dirFile.Name);
458+
if (result) {
459+
Process.Start(dirFile.FullName);
460+
opened = true;
461+
break;
462+
}
463+
}
464+
}
465+
466+
if (!opened) {
467+
Error("File(" + parameter + ") doesn't exist at" + " (" + fileLocation + ")");
468+
} else {
469+
if (!MainProgram.testingAction) {
470+
successMessage = "OPEN: opened " + parameter;
471+
} else {
472+
successMessage = "OPEN: simulated opening " + parameter;
473+
}
474+
}
475+
} else {
476+
Error("Directory doesn't exist (" + fileLocation + ")");
477+
}
478+
}
448479
public void OpenAll(string parameter) {
449480
string fileLocation = (!parameter.Contains(@":\") || !parameter.Contains(@":/")) ? Path.Combine(MainProgram.shortcutLocation, parameter) : parameter;
450481

AssistantComputerControl/App.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@
8686
<setting name="StartsUsingRegistry" serializeAs="String">
8787
<value>False</value>
8888
</setting>
89+
<setting name="ActionMessageBox" serializeAs="String">
90+
<value>True</value>
91+
</setting>
8992
</AssistantComputerControl.Properties.Settings>
9093
</userSettings>
9194
<runtime>

AssistantComputerControl/MainProgram.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,8 @@ public static void TaskSchedulerSetup () {
437437
td.RegistrationInfo.Author = "Albert MN. | AssistantComputerControl";
438438
td.RegistrationInfo.Description = "AssistantComputerControl cleanup - clears the action folder to prevent the same action being executed twice";
439439

440-
td.Actions.Add(new ExecAction("powershell.exe", $"-WindowStyle Hidden -file \"{ps1File}\" \"{Path.Combine(MainProgram.CheckPath(), "*")}\" \"*.{Properties.Settings.Default.ActionFileExtension}\"", null));
441-
440+
td.Actions.Add(new ExecAction("mshta.exe", $"vbscript:Execute(\"CreateObject(\"\"WScript.Shell\"\").Run \"\"powershell -ExecutionPolicy Bypass & '{ps1File}' '{Path.Combine(MainProgram.CheckPath(), "*")}' '*.{Properties.Settings.Default.ActionFileExtension}'\"\", 0:close\")", null));
441+
442442
td.Triggers.Add(new LogonTrigger { UserId = userId, });
443443
ts.RootFolder.RegisterTaskDefinition(@"AssistantComputerControl cleanup", td);
444444
}
@@ -936,4 +936,4 @@ public static bool IsValidPath(string path, bool allowRelativePaths = false) {
936936
return isValid;
937937
}
938938
}
939-
}
939+
}

AssistantComputerControl/Properties/Settings.Designer.cs

Lines changed: 14 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AssistantComputerControl/Properties/Settings.settings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,8 @@
8383
<Setting Name="StartsUsingRegistry" Type="System.Boolean" Scope="User">
8484
<Value Profile="(Default)">False</Value>
8585
</Setting>
86+
<Setting Name="ActionMessageBox" Type="System.Boolean" Scope="User">
87+
<Value Profile="(Default)">True</Value>
88+
</Setting>
8689
</Settings>
8790
</SettingsFile>

AssistantComputerControl/SettingsForm.Designer.cs

Lines changed: 25 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AssistantComputerControl/SettingsForm.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ void FreakingStopDingSound(Object o, KeyEventArgs e) {
3838
//Set values
3939
startWithWindows.Checked = MainProgram.ACCStartsWithWindows();
4040
checkUpdates.Checked = Properties.Settings.Default.CheckForUpdates;
41+
actionErrorMessageBox.Checked = Properties.Settings.Default.ActionMessageBox;
4142
betaProgram.Checked = Properties.Settings.Default.BetaProgram;
4243
warnDeletion.Checked = Properties.Settings.Default.WarnWhenDeletingManyFiles;
4344
defaultComputer.Checked = Properties.Settings.Default.DefaultComputer;
@@ -106,6 +107,14 @@ private void checkUpdates_CheckedChanged(object sender, EventArgs e) {
106107
}
107108
}
108109

110+
private void actionErrorMessageBox_CheckedChanged(object sender, EventArgs e) {
111+
if (Properties.Settings.Default.ActionMessageBox != actionErrorMessageBox.Checked) {
112+
Properties.Settings.Default.ActionMessageBox = actionErrorMessageBox.Checked;
113+
Properties.Settings.Default.Save();
114+
}
115+
116+
}
117+
109118
private void betaProgram_CheckedChanged(object sender, EventArgs e) {
110119
if (Properties.Settings.Default.BetaProgram != betaProgram.Checked) {
111120
Properties.Settings.Default.BetaProgram = betaProgram.Checked;
@@ -214,5 +223,7 @@ private void saveLanguageButton_Click(object sender, EventArgs e) {
214223
private void changelogOpen_Click(object sender, EventArgs e) {
215224
new NewVersion().Show();
216225
}
226+
227+
217228
}
218-
}
229+
}

AssistantComputerControl/Translations/Danish.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"save_language_btn": "gem",
3232
"start_with_windows": "Åben med Windows?",
3333
"check_for_updates": "Søg automatisk efter opdateringer?",
34+
"action_error_message_box": "Show action errors?",
3435
"join_beta_program": "Vær en del af beta-programmet (og få opdateringer tidligt)",
3536

3637
"file_edited_margin": "Filændring margen (sekunder)",

AssistantComputerControl/Translations/Dutch.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"save_language_btn": "bewaren",
3434
"start_with_windows": "Start met Windows?",
3535
"check_for_updates": "Controleren op updates?",
36+
"action_error_message_box": "Show action errors?",
3637
"join_beta_program": "Sluit je aan bij het beta programma?",
3738

3839
"file_edited_margin": "Bestand bewerkt marge (seconden)",

AssistantComputerControl/Translations/English.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"save_language_btn": "save",
3434
"start_with_windows": "Start with Windows?",
3535
"check_for_updates": "Check for updates?",
36+
"action_error_message_box": "Show action errors?",
3637
"join_beta_program": "Join the beta program?",
3738

3839
"file_edited_margin": "File edited margin (seconds)",

0 commit comments

Comments
 (0)