Skip to content

Fix drives loading #701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion Files.Launcher/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.ComponentModel;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.IO.Pipes;
using System.Runtime.InteropServices;
using System.Security.Principal;
using Windows.Storage;

Expand All @@ -25,6 +27,19 @@ private static void Main(string[] args)
var path = (string)localSettings.Values["path"];
QuickLook.ToggleQuickLook(path);
}
else if (arguments.Equals("ShellCommand"))
{
//Kill the process. This is a BRUTAL WAY to kill a process.
var pid = (int)ApplicationData.Current.LocalSettings.Values["pid"];
Process.GetProcessById(pid).Kill();

Process process = new Process();
process.StartInfo.UseShellExecute = true;
process.StartInfo.FileName = "explorer.exe";
process.StartInfo.CreateNoWindow = false;
process.StartInfo.Arguments = (string)ApplicationData.Current.LocalSettings.Values["ShellCommand"];
process.Start();
}
else
{
var executable = (string)ApplicationData.Current.LocalSettings.Values["Application"];
Expand Down
35 changes: 6 additions & 29 deletions Files/App.xaml
Original file line number Diff line number Diff line change
@@ -1,53 +1,28 @@
<Application
<Application
x:Class="Files.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Windows10version1903="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract, 8)">
xmlns:converters="using:Files.Helpers">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
<ResourceDictionary Source="/ResourceDictionaries/ToolbarButtonStyle.xaml" />
<ResourceDictionary>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<SolidColorBrush x:Key="NavigationViewDefaultPaneBackground" Color="White" />
<SolidColorBrush x:Key="NavigationViewExpandedPaneBackground" Color="White" />
<AcrylicBrush
x:Key="BackgroundAcrylicBrush"
Windows10version1903:TintLuminosityOpacity="0.9"
BackgroundSource="HostBackdrop"
FallbackColor="{StaticResource SystemListLowColor}"
TintColor="White"
TintOpacity="0.9" />
<SolidColorBrush x:Key="RibbonBackgroundColor" Color="White" />
<StaticResource x:Key="NavigationViewTopPaneBackground" ResourceKey="RibbonBackgroundColor" />
</ResourceDictionary>
<ResourceDictionary x:Key="Light">
<AcrylicBrush
x:Key="BackgroundAcrylicBrush"
Windows10version1903:TintLuminosityOpacity="0.9"
BackgroundSource="HostBackdrop"
FallbackColor="{StaticResource SystemChromeWhiteColor}"
TintColor="White"
TintOpacity="0.9" />
<SolidColorBrush x:Key="NavigationViewDefaultPaneBackground" Color="White" />
<SolidColorBrush x:Key="NavigationViewExpandedPaneBackground" Color="White" />
<SolidColorBrush x:Key="UnmodifiedSystemPageColor" Color="White" />
<SolidColorBrush x:Key="YourHomeCardBackgroundColor" Color="#f3f1ef" />
<SolidColorBrush x:Key="YourHomeCardBorderColor" Color="#f3f1ef" />
<SolidColorBrush x:Key="TabViewBackground" Color="White" />
<SolidColorBrush x:Key="CustomInputFieldBorderBrush" Color="DarkGray" />
<SolidColorBrush x:Key="RibbonBackgroundColor" Color="White" />
<StaticResource x:Key="NavigationViewTopPaneBackground" ResourceKey="RibbonBackgroundColor" />
<SolidColorBrush x:Key="SystemControlPageBackgroundMediumAltMediumBrush" Color="#99000000" />
</ResourceDictionary>
<ResourceDictionary x:Key="Dark">
<AcrylicBrush
x:Key="BackgroundAcrylicBrush"
Windows10version1903:TintLuminosityOpacity="0.9"
BackgroundSource="HostBackdrop"
FallbackColor="{StaticResource SystemListLowColor}"
TintColor="Black"
TintOpacity="0.7" />
<SolidColorBrush x:Key="NavigationViewDefaultPaneBackground" Color="#191919" />
<SolidColorBrush x:Key="NavigationViewExpandedPaneBackground" Color="#191919" />
<SolidColorBrush x:Key="ApplicationPageBackgroundThemeBrush" Color="#191919" />
Expand All @@ -62,13 +37,15 @@
<!--<SolidColorBrush x:Key="TextControlBorderBrush" Color="#FF363636" />-->
<SolidColorBrush x:Key="RibbonBackgroundColor" Color="#131313" />
<StaticResource x:Key="NavigationViewTopPaneBackground" ResourceKey="RibbonBackgroundColor" />
<SolidColorBrush x:Key="SystemControlPageBackgroundMediumAltMediumBrush" Color="#99000000" />
</ResourceDictionary>
<ResourceDictionary x:Key="HighContrast">
<!-- This empty dictionary ensures that the default high contrast resources are used when the user turns on high contrast mode. -->
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
<converters:NegateConverter x:Key="NegateConverter" />
</ResourceDictionary>
</Application.Resources>
</Application>
83 changes: 74 additions & 9 deletions Files/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Files.CommandLine;
using Files.CommandLine;
using Files.Controls;
using Files.Filesystem;
using Files.Helpers;
using Files.Interacts;
using Files.View_Models;
using Microsoft.AppCenter;
Expand All @@ -11,16 +12,18 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.ApplicationModel.Core;
using Windows.ApplicationModel.DataTransfer;
using Windows.Storage;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Animation;
using Windows.UI.Xaml.Navigation;

Expand Down Expand Up @@ -61,8 +64,36 @@ public static IShellPage CurrentInstance

public App()
{
this.InitializeComponent();
this.Suspending += OnSuspending;
var args = Environment.GetCommandLineArgs();

if (args.Length == 2)
{
var parsedCommands = CommandLineParser.ParseUntrustedCommands(args);

if (parsedCommands != null && parsedCommands.Count > 0)
{
foreach (var command in parsedCommands)
{
switch (command.Type)
{
case ParsedCommandType.ExplorerShellCommand:
var proc = Process.GetCurrentProcess();
OpenShellCommandInExplorer(command.Payload, proc.Id).GetAwaiter().GetResult();

//this is useless.
Exit();
return;
default:
break;
}
}
}


}

InitializeComponent();
Suspending += OnSuspending;

// Initialize NLog
Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
Expand Down Expand Up @@ -202,13 +233,14 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
rootFrame.Navigate(typeof(InstanceTabsView), e.Arguments, new SuppressNavigationTransitionInfo());
}

ThemeHelper.Initialize();
// Ensure the current window is active
Window.Current.Activate();
Window.Current.CoreWindow.PointerPressed += CoreWindow_PointerPressed;
}
}

protected override void OnActivated(IActivatedEventArgs args)
protected override async void OnActivated(IActivatedEventArgs args)
{
Logger.Info("App activated");

Expand Down Expand Up @@ -253,16 +285,40 @@ protected override void OnActivated(IActivatedEventArgs args)
switch (command.Type)
{
case ParsedCommandType.OpenDirectory:
// TODO Open Directory

rootFrame.Navigate(typeof(InstanceTabsView), command.Payload, new SuppressNavigationTransitionInfo());

// Ensure the current window is active.
Window.Current.Activate();
Window.Current.CoreWindow.PointerPressed += CoreWindow_PointerPressed;
return;

case ParsedCommandType.Unkwon:
case ParsedCommandType.OpenPath:

try
{
var det = await StorageFolder.GetFolderFromPathAsync(command.Payload);

rootFrame.Navigate(typeof(InstanceTabsView), command.Payload, new SuppressNavigationTransitionInfo());

// Ensure the current window is active.
Window.Current.Activate();
Window.Current.CoreWindow.PointerPressed += CoreWindow_PointerPressed;

return;
}
catch (System.IO.FileNotFoundException ex)
{
//Not a folder
Debug.WriteLine($"File not found exception App.xaml.cs\\OnActivated with message: {ex.Message}");
}
catch (Exception ex)
{
Debug.WriteLine($"Exception in App.xaml.cs\\OnActivated with message: {ex.Message}");
}

break;

case ParsedCommandType.Unknown:
rootFrame.Navigate(typeof(InstanceTabsView), null, new SuppressNavigationTransitionInfo());
// Ensure the current window is active.
Window.Current.Activate();
Expand All @@ -281,6 +337,15 @@ protected override void OnActivated(IActivatedEventArgs args)
Window.Current.CoreWindow.PointerPressed += CoreWindow_PointerPressed;
}

public static async Task OpenShellCommandInExplorer(string shellCommand, int pid)
{
System.Diagnostics.Debug.WriteLine("Launching shell command in FullTrustProcess");
ApplicationData.Current.LocalSettings.Values["ShellCommand"] = shellCommand;
ApplicationData.Current.LocalSettings.Values["Arguments"] = "ShellCommand";
ApplicationData.Current.LocalSettings.Values["pid"] = pid;
await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();
}

private void TryEnablePrelaunch()
{
Windows.ApplicationModel.Core.CoreApplication.EnablePrelaunch(true);
Expand Down
81 changes: 65 additions & 16 deletions Files/CommandLine/CommandLineParser.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -11,9 +12,19 @@ internal class CommandLineParser
{
public static ParsedCommands ParseUntrustedCommands(string cmdLineString)
{
var commands = new ParsedCommands();
var parsedArgs = Parse(SplitArguments(cmdLineString));
return ParseSplitArguments(parsedArgs);
}

var parsedArgs = Parse(cmdLineString);
public static ParsedCommands ParseUntrustedCommands(string[] cmdLineStrings)
{
var parsedArgs = Parse(cmdLineStrings);
return ParseSplitArguments(parsedArgs);
}

private static ParsedCommands ParseSplitArguments(List<KeyValuePair<string, string>> parsedArgs)
{
var commands = new ParsedCommands();

foreach (var kvp in parsedArgs)
{
Expand All @@ -28,7 +39,21 @@ public static ParsedCommands ParseUntrustedCommands(string cmdLineString)
break;

default:
command.Type = ParsedCommandType.Unkwon;
//case "-Cmdless":
try
{
if (kvp.Value.StartsWith("::{") || kvp.Value.StartsWith("shell:"))
command.Type = ParsedCommandType.ExplorerShellCommand;
else if (Path.IsPathRooted(kvp.Value))
command.Type = ParsedCommandType.OpenPath;
else
command.Type = ParsedCommandType.Unknown;
}
catch (Exception ex)
{
Debug.WriteLine($"Exception in CommandLineParser.cs\\ParseUntrustedCommands with message: {ex.Message}");
command.Type = ParsedCommandType.Unknown;
}
break;
}

Expand All @@ -39,36 +64,60 @@ public static ParsedCommands ParseUntrustedCommands(string cmdLineString)
return commands;
}

public static List<KeyValuePair<string, string>> Parse(string argString = null)
static string[] SplitArguments(string commandLine)
{
var parsedArgs = new List<KeyValuePair<string, string>>();
char[] commandLineCharArray = commandLine.ToCharArray();
bool isInQuote = false;

string[] args = argString.Split(" ");
for (int i = 0; i < commandLineCharArray.Length; i++)
{
if (commandLineCharArray[i] == '"')
isInQuote = !isInQuote;

if (!isInQuote && commandLineCharArray[i] == ' ')
commandLineCharArray[i] = '\n';
}

return new string(commandLineCharArray).Replace("\"", "").Split('\n');
}

public static List<KeyValuePair<string, string>> Parse(string[] args = null)
{
var parsedArgs = new List<KeyValuePair<string, string>>();
//Environment.GetCommandLineArgs() IS better but... I haven't tested this enough.

if (args != null)
{
for (int i = 0; i < args.Length; i++)
//if - or / are not used then add the command as-is

if (args.Length > 2)
{
if (args[i].StartsWith("-") || args[i].StartsWith("/"))
for (int i = 0; i < args.Length; i++)
{
var data = ParseData(args, i);

if (data.Key != null)
if (args[i].StartsWith("-") || args[i].StartsWith("/"))
{
for (int j = 0; j < parsedArgs.Count; j++)
var data = ParseData(args, i);

if (data.Key != null)
{
if (parsedArgs[j].Key == data.Key)
for (int j = 0; j < parsedArgs.Count; j++)
{
parsedArgs.RemoveAt(j);
if (parsedArgs[j].Key == data.Key)
{
parsedArgs.RemoveAt(j);
}
}
}

parsedArgs.Add(data);
parsedArgs.Add(data);
}
}
}
}
}

if (parsedArgs.Count == 0 && args.Length >= 2)
parsedArgs.Add(new KeyValuePair<string, string>("-Cmdless", string.Join(" ", args.Skip(1))));

return parsedArgs;
}

Expand Down
4 changes: 3 additions & 1 deletion Files/CommandLine/ParsedCommandType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ namespace Files.CommandLine
{
internal enum ParsedCommandType
{
Unkwon,
Unknown,
OpenDirectory,
OpenPath,
ExplorerShellCommand
}
}
Loading