Skip to content

Commit f1d7add

Browse files
committed
Launch all files with Process.Start
1 parent ab9f03a commit f1d7add

File tree

4 files changed

+51
-57
lines changed

4 files changed

+51
-57
lines changed

Files.Launcher/Program.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Diagnostics;
1+
using System.ComponentModel;
2+
using System.Diagnostics;
23
using System.IO;
34
using System.IO.Pipes;
45
using System.Security.Principal;
@@ -55,15 +56,22 @@ static void Main(string[] args)
5556
process.StartInfo.CreateNoWindow = true;
5657
process.Start();
5758
}
58-
catch (System.ComponentModel.Win32Exception)
59+
catch (Win32Exception)
5960
{
6061
var executable = (string)ApplicationData.Current.LocalSettings.Values["Application"];
6162
Process process = new Process();
6263
process.StartInfo.UseShellExecute = true;
6364
process.StartInfo.Verb = "runas";
6465
process.StartInfo.FileName = executable;
6566
process.StartInfo.CreateNoWindow = true;
66-
process.Start();
67+
try
68+
{
69+
process.Start();
70+
}
71+
catch (Win32Exception)
72+
{
73+
Process.Start(executable);
74+
}
6775
}
6876

6977

Files/Controls/RibbonArea.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,11 @@ public async void CheckPathInput(ItemViewModel instance, string CurrentInput)
155155
{
156156
if (parentPage.ItemDisplayFrame.SourcePageType == typeof(GenericFileBrowser))
157157
{
158-
await Interaction.LaunchExe(CurrentInput);
158+
await Interaction.InvokeWin32Component(CurrentInput);
159159
}
160160
else if (parentPage.ItemDisplayFrame.SourcePageType == typeof(PhotoAlbum))
161161
{
162-
await Interaction.LaunchExe(CurrentInput);
162+
await Interaction.InvokeWin32Component(CurrentInput);
163163
}
164164

165165
VisiblePath.Text = instance.Universal.path;

Files/Interacts/Interaction.cs

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public void GetPath_Click(object sender, RoutedEventArgs e)
257257
}
258258
}
259259

260-
public static async Task LaunchExe(string ApplicationPath)
260+
public static async Task InvokeWin32Component(string ApplicationPath)
261261
{
262262
Debug.WriteLine("Launching EXE in FullTrustProcess");
263263
ApplicationData.Current.LocalSettings.Values["Application"] = ApplicationPath;
@@ -411,22 +411,30 @@ private async void OpenSelectedItems(bool displayApplicationPicker)
411411
currentInstance.ItemDisplayFrame.Navigate(sourcePageType, selectedItemPath, new SuppressNavigationTransitionInfo());
412412
}
413413
}
414-
else if (clickedOnItem.FileType == "Application")
415-
{
416-
// Add location to MRU List
417-
mostRecentlyUsed.Add(await StorageFile.GetFileFromPathAsync(clickedOnItem.FilePath));
418-
await LaunchExe(clickedOnItem.FilePath);
419-
}
420414
else
421415
{
422-
StorageFile file = await StorageFile.GetFileFromPathAsync(clickedOnItem.FilePath);
423-
// Add location to MRU List
424-
mostRecentlyUsed.Add(file);
425-
var options = new LauncherOptions
416+
if (clickedOnItem.FileType == "Folder")
417+
{
418+
instanceTabsView.AddNewTab(typeof(ProHome), clickedOnItem.FilePath);
419+
}
420+
else
426421
{
427-
DisplayApplicationPicker = displayApplicationPicker
428-
};
429-
await Launcher.LaunchFileAsync(file, options);
422+
// Add location to MRU List
423+
mostRecentlyUsed.Add(await StorageFile.GetFileFromPathAsync(clickedOnItem.FilePath));
424+
if (displayApplicationPicker)
425+
{
426+
StorageFile file = await StorageFile.GetFileFromPathAsync(clickedOnItem.FilePath);
427+
var options = new LauncherOptions
428+
{
429+
DisplayApplicationPicker = true
430+
};
431+
await Launcher.LaunchFileAsync(file, options);
432+
}
433+
else
434+
{
435+
await InvokeWin32Component(clickedOnItem.FilePath);
436+
}
437+
}
430438
}
431439
}
432440
else if(selectedItemCount > 1)
@@ -438,22 +446,23 @@ private async void OpenSelectedItems(bool displayApplicationPicker)
438446
{
439447
instanceTabsView.AddNewTab(typeof(ProHome), clickedOnItem.FilePath);
440448
}
441-
else if (clickedOnItem.FileType == "Application")
442-
{
443-
// Add location to MRU List
444-
mostRecentlyUsed.Add(await StorageFile.GetFileFromPathAsync(clickedOnItem.FilePath));
445-
await LaunchExe(clickedOnItem.FilePath);
446-
}
447449
else
448450
{
449-
StorageFile file = await StorageFile.GetFileFromPathAsync(clickedOnItem.FilePath);
450451
// Add location to MRU List
451-
mostRecentlyUsed.Add(file);
452-
var options = new LauncherOptions
452+
mostRecentlyUsed.Add(await StorageFile.GetFileFromPathAsync(clickedOnItem.FilePath));
453+
if (displayApplicationPicker)
453454
{
454-
DisplayApplicationPicker = displayApplicationPicker
455-
};
456-
await Launcher.LaunchFileAsync(file, options);
455+
StorageFile file = await StorageFile.GetFileFromPathAsync(clickedOnItem.FilePath);
456+
var options = new LauncherOptions
457+
{
458+
DisplayApplicationPicker = true
459+
};
460+
await Launcher.LaunchFileAsync(file, options);
461+
}
462+
else
463+
{
464+
await InvokeWin32Component(clickedOnItem.FilePath);
465+
}
457466
}
458467
}
459468
}

Files/YourHome.xaml.cs

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -281,17 +281,7 @@ public async void PopulateRecentsList()
281281
try
282282
{
283283
Windows.Storage.IStorageItem item = await mostRecentlyUsed.GetItemAsync(mruToken);
284-
if (item.IsOfType(StorageItemTypes.Folder))
285-
{
286-
ItemName = item.Name;
287-
ItemPath = item.Path;
288-
ItemType = StorageItemTypes.Folder;
289-
ItemFolderImgVis = Visibility.Visible;
290-
ItemEmptyImgVis = Visibility.Collapsed;
291-
ItemFileIconVis = Visibility.Collapsed;
292-
recentItemsCollection.Add(new RecentItem() { name = ItemName, path = ItemPath, type = ItemType, EmptyImgVis = ItemEmptyImgVis, FolderImg = ItemFolderImgVis, FileImg = ItemImage, FileIconVis = ItemFileIconVis });
293-
}
294-
else if (item.IsOfType(StorageItemTypes.File))
284+
if (item.IsOfType(StorageItemTypes.File))
295285
{
296286
ItemName = item.Name;
297287
ItemPath = item.Path;
@@ -329,20 +319,7 @@ private async void RecentsView_ItemClick(object sender, ItemClickEventArgs e)
329319
var path = (e.ClickedItem as RecentItem).path;
330320
try
331321
{
332-
var file = (await StorageFile.GetFileFromPathAsync(path));
333-
if (file.DisplayType == "Application")
334-
{
335-
await Interaction.LaunchExe(path);
336-
337-
}
338-
else
339-
{
340-
var options = new LauncherOptions
341-
{
342-
DisplayApplicationPicker = false
343-
};
344-
await Launcher.LaunchFileAsync(file, options);
345-
}
322+
await Interaction.InvokeWin32Component(path);
346323
}
347324
catch (UnauthorizedAccessException)
348325
{
@@ -357,7 +334,7 @@ private async void RecentsView_ItemClick(object sender, ItemClickEventArgs e)
357334
}
358335
else
359336
{
360-
foreach(DriveItem drive in App.foundDrives)
337+
foreach (DriveItem drive in App.foundDrives)
361338
{
362339
if (drive.tag.ToString() == new DirectoryInfo(path).Root.ToString())
363340
{

0 commit comments

Comments
 (0)