Skip to content

Commit 5322f37

Browse files
yaira2RichardtsvietOKADeltaXt-k365
authored
v0.7.9 (#715)
Co-authored-by: Richard <[email protected]> Co-authored-by: Vladyslav <[email protected]> Co-authored-by: ADeltaX <[email protected]> Co-authored-by: Thomas <[email protected]> Co-authored-by: Simone <[email protected]> Co-authored-by: Jeff Sieu <[email protected]> Co-authored-by: Luke Blevins <[email protected]> Co-authored-by: Richard <[email protected]>
1 parent 9e8ad53 commit 5322f37

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1249
-442
lines changed

Files.Launcher/Program.cs

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
using System.ComponentModel;
1+
using System;
2+
using System.ComponentModel;
23
using System.Diagnostics;
34
using System.IO;
45
using System.IO.Pipes;
6+
using System.Runtime.InteropServices;
57
using System.Security.Principal;
68
using Windows.Storage;
79

@@ -25,6 +27,19 @@ private static void Main(string[] args)
2527
var path = (string)localSettings.Values["path"];
2628
QuickLook.ToggleQuickLook(path);
2729
}
30+
else if (arguments.Equals("ShellCommand"))
31+
{
32+
//Kill the process. This is a BRUTAL WAY to kill a process.
33+
var pid = (int)ApplicationData.Current.LocalSettings.Values["pid"];
34+
Process.GetProcessById(pid).Kill();
35+
36+
Process process = new Process();
37+
process.StartInfo.UseShellExecute = true;
38+
process.StartInfo.FileName = "explorer.exe";
39+
process.StartInfo.CreateNoWindow = false;
40+
process.StartInfo.Arguments = (string)ApplicationData.Current.LocalSettings.Values["ShellCommand"];
41+
process.Start();
42+
}
2843
else
2944
{
3045
var executable = (string)ApplicationData.Current.LocalSettings.Values["Application"];

Files.Package/Package.appxmanifest

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" xmlns:desktop4="http://schemas.microsoft.com/appx/manifest/desktop/windows10/4" xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10" xmlns:uap5="http://schemas.microsoft.com/appx/manifest/uap/windows10/5" IgnorableNamespaces="uap uap5 mp rescap desktop4 desktop">
3-
<Identity Name="FilesUWPDev" Publisher="CN=53EC4384-7F5B-4CF6-8C23-513FFE9D1AB7" Version="0.7.8.0" />
3+
<Identity Name="FilesUWPDev" Publisher="CN=53EC4384-7F5B-4CF6-8C23-513FFE9D1AB7" Version="0.7.9.0" />
44
<Properties>
55
<DisplayName>Files UWP - Dev</DisplayName>
66
<PublisherDisplayName>Yair A</PublisherDisplayName>

Files/App.xaml

+6-29
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,28 @@
1-
<Application
1+
<Application
22
x:Class="Files.App"
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5-
xmlns:Windows10version1903="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract, 8)">
5+
xmlns:converters="using:Files.Helpers">
66
<Application.Resources>
77
<ResourceDictionary>
88
<ResourceDictionary.MergedDictionaries>
99
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
1010
<ResourceDictionary Source="/ResourceDictionaries/ToolbarButtonStyle.xaml" />
1111
<ResourceDictionary>
1212
<ResourceDictionary.ThemeDictionaries>
13-
<ResourceDictionary x:Key="Default">
14-
<SolidColorBrush x:Key="NavigationViewDefaultPaneBackground" Color="White" />
15-
<SolidColorBrush x:Key="NavigationViewExpandedPaneBackground" Color="White" />
16-
<AcrylicBrush
17-
x:Key="BackgroundAcrylicBrush"
18-
Windows10version1903:TintLuminosityOpacity="0.9"
19-
BackgroundSource="HostBackdrop"
20-
FallbackColor="{StaticResource SystemListLowColor}"
21-
TintColor="White"
22-
TintOpacity="0.9" />
23-
<SolidColorBrush x:Key="RibbonBackgroundColor" Color="White" />
24-
<StaticResource x:Key="NavigationViewTopPaneBackground" ResourceKey="RibbonBackgroundColor" />
25-
</ResourceDictionary>
2613
<ResourceDictionary x:Key="Light">
27-
<AcrylicBrush
28-
x:Key="BackgroundAcrylicBrush"
29-
Windows10version1903:TintLuminosityOpacity="0.9"
30-
BackgroundSource="HostBackdrop"
31-
FallbackColor="{StaticResource SystemChromeWhiteColor}"
32-
TintColor="White"
33-
TintOpacity="0.9" />
3414
<SolidColorBrush x:Key="NavigationViewDefaultPaneBackground" Color="White" />
3515
<SolidColorBrush x:Key="NavigationViewExpandedPaneBackground" Color="White" />
3616
<SolidColorBrush x:Key="UnmodifiedSystemPageColor" Color="White" />
3717
<SolidColorBrush x:Key="YourHomeCardBackgroundColor" Color="#f3f1ef" />
3818
<SolidColorBrush x:Key="YourHomeCardBorderColor" Color="#f3f1ef" />
19+
<SolidColorBrush x:Key="TabViewBackground" Color="White" />
3920
<SolidColorBrush x:Key="CustomInputFieldBorderBrush" Color="DarkGray" />
4021
<SolidColorBrush x:Key="RibbonBackgroundColor" Color="White" />
4122
<StaticResource x:Key="NavigationViewTopPaneBackground" ResourceKey="RibbonBackgroundColor" />
23+
<SolidColorBrush x:Key="SystemControlPageBackgroundMediumAltMediumBrush" Color="#99000000" />
4224
</ResourceDictionary>
4325
<ResourceDictionary x:Key="Dark">
44-
<AcrylicBrush
45-
x:Key="BackgroundAcrylicBrush"
46-
Windows10version1903:TintLuminosityOpacity="0.9"
47-
BackgroundSource="HostBackdrop"
48-
FallbackColor="{StaticResource SystemListLowColor}"
49-
TintColor="Black"
50-
TintOpacity="0.7" />
5126
<SolidColorBrush x:Key="NavigationViewDefaultPaneBackground" Color="#191919" />
5227
<SolidColorBrush x:Key="NavigationViewExpandedPaneBackground" Color="#191919" />
5328
<SolidColorBrush x:Key="ApplicationPageBackgroundThemeBrush" Color="#191919" />
@@ -62,13 +37,15 @@
6237
<!--<SolidColorBrush x:Key="TextControlBorderBrush" Color="#FF363636" />-->
6338
<SolidColorBrush x:Key="RibbonBackgroundColor" Color="#131313" />
6439
<StaticResource x:Key="NavigationViewTopPaneBackground" ResourceKey="RibbonBackgroundColor" />
40+
<SolidColorBrush x:Key="SystemControlPageBackgroundMediumAltMediumBrush" Color="#99000000" />
6541
</ResourceDictionary>
6642
<ResourceDictionary x:Key="HighContrast">
6743
<!-- This empty dictionary ensures that the default high contrast resources are used when the user turns on high contrast mode. -->
6844
</ResourceDictionary>
6945
</ResourceDictionary.ThemeDictionaries>
7046
</ResourceDictionary>
7147
</ResourceDictionary.MergedDictionaries>
48+
<converters:NegateConverter x:Key="NegateConverter" />
7249
</ResourceDictionary>
7350
</Application.Resources>
7451
</Application>

Files/App.xaml.cs

+77-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
using Files.CommandLine;
1+
using Files.CommandLine;
22
using Files.Controls;
33
using Files.Filesystem;
4+
using Files.Helpers;
45
using Files.Interacts;
56
using Files.View_Models;
67
using Microsoft.AppCenter;
@@ -11,16 +12,18 @@
1112
using System;
1213
using System.Collections.Generic;
1314
using System.Collections.ObjectModel;
15+
using System.Diagnostics;
1416
using System.Linq;
17+
using System.Runtime.InteropServices;
18+
using System.Threading.Tasks;
1519
using Windows.ApplicationModel;
1620
using Windows.ApplicationModel.Activation;
21+
using Windows.ApplicationModel.Core;
1722
using Windows.ApplicationModel.DataTransfer;
1823
using Windows.Storage;
1924
using Windows.UI.Core;
2025
using Windows.UI.Xaml;
2126
using Windows.UI.Xaml.Controls;
22-
using Windows.UI.Xaml.Controls.Primitives;
23-
using Windows.UI.Xaml.Media;
2427
using Windows.UI.Xaml.Media.Animation;
2528
using Windows.UI.Xaml.Navigation;
2629

@@ -61,8 +64,36 @@ public static IShellPage CurrentInstance
6164

6265
public App()
6366
{
64-
this.InitializeComponent();
65-
this.Suspending += OnSuspending;
67+
var args = Environment.GetCommandLineArgs();
68+
69+
if (args.Length == 2)
70+
{
71+
var parsedCommands = CommandLineParser.ParseUntrustedCommands(args);
72+
73+
if (parsedCommands != null && parsedCommands.Count > 0)
74+
{
75+
foreach (var command in parsedCommands)
76+
{
77+
switch (command.Type)
78+
{
79+
case ParsedCommandType.ExplorerShellCommand:
80+
var proc = Process.GetCurrentProcess();
81+
OpenShellCommandInExplorer(command.Payload, proc.Id).GetAwaiter().GetResult();
82+
83+
//this is useless.
84+
Exit();
85+
return;
86+
default:
87+
break;
88+
}
89+
}
90+
}
91+
92+
93+
}
94+
95+
InitializeComponent();
96+
Suspending += OnSuspending;
6697

6798
// Initialize NLog
6899
Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
@@ -202,13 +233,15 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
202233
rootFrame.Navigate(typeof(InstanceTabsView), e.Arguments, new SuppressNavigationTransitionInfo());
203234
}
204235

236+
ThemeHelper.Initialize();
237+
205238
// Ensure the current window is active
206239
Window.Current.Activate();
207240
Window.Current.CoreWindow.PointerPressed += CoreWindow_PointerPressed;
208241
}
209242
}
210243

211-
protected override void OnActivated(IActivatedEventArgs args)
244+
protected override async void OnActivated(IActivatedEventArgs args)
212245
{
213246
Logger.Info("App activated");
214247

@@ -219,6 +252,8 @@ protected override void OnActivated(IActivatedEventArgs args)
219252
Window.Current.Content = rootFrame;
220253
}
221254

255+
ThemeHelper.Initialize();
256+
222257
switch (args.Kind)
223258
{
224259
case ActivationKind.Protocol:
@@ -253,16 +288,40 @@ protected override void OnActivated(IActivatedEventArgs args)
253288
switch (command.Type)
254289
{
255290
case ParsedCommandType.OpenDirectory:
256-
// TODO Open Directory
257-
258291
rootFrame.Navigate(typeof(InstanceTabsView), command.Payload, new SuppressNavigationTransitionInfo());
259292

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

265-
case ParsedCommandType.Unkwon:
298+
case ParsedCommandType.OpenPath:
299+
300+
try
301+
{
302+
var det = await StorageFolder.GetFolderFromPathAsync(command.Payload);
303+
304+
rootFrame.Navigate(typeof(InstanceTabsView), command.Payload, new SuppressNavigationTransitionInfo());
305+
306+
// Ensure the current window is active.
307+
Window.Current.Activate();
308+
Window.Current.CoreWindow.PointerPressed += CoreWindow_PointerPressed;
309+
310+
return;
311+
}
312+
catch (System.IO.FileNotFoundException ex)
313+
{
314+
//Not a folder
315+
Debug.WriteLine($"File not found exception App.xaml.cs\\OnActivated with message: {ex.Message}");
316+
}
317+
catch (Exception ex)
318+
{
319+
Debug.WriteLine($"Exception in App.xaml.cs\\OnActivated with message: {ex.Message}");
320+
}
321+
322+
break;
323+
324+
case ParsedCommandType.Unknown:
266325
rootFrame.Navigate(typeof(InstanceTabsView), null, new SuppressNavigationTransitionInfo());
267326
// Ensure the current window is active.
268327
Window.Current.Activate();
@@ -281,6 +340,15 @@ protected override void OnActivated(IActivatedEventArgs args)
281340
Window.Current.CoreWindow.PointerPressed += CoreWindow_PointerPressed;
282341
}
283342

343+
public static async Task OpenShellCommandInExplorer(string shellCommand, int pid)
344+
{
345+
System.Diagnostics.Debug.WriteLine("Launching shell command in FullTrustProcess");
346+
ApplicationData.Current.LocalSettings.Values["ShellCommand"] = shellCommand;
347+
ApplicationData.Current.LocalSettings.Values["Arguments"] = "ShellCommand";
348+
ApplicationData.Current.LocalSettings.Values["pid"] = pid;
349+
await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();
350+
}
351+
284352
private void TryEnablePrelaunch()
285353
{
286354
Windows.ApplicationModel.Core.CoreApplication.EnablePrelaunch(true);

Files/CommandLine/CommandLineParser.cs

+65-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics;
4+
using System.IO;
45
using System.Linq;
56
using System.Text;
67
using System.Threading.Tasks;
@@ -11,9 +12,19 @@ internal class CommandLineParser
1112
{
1213
public static ParsedCommands ParseUntrustedCommands(string cmdLineString)
1314
{
14-
var commands = new ParsedCommands();
15+
var parsedArgs = Parse(SplitArguments(cmdLineString));
16+
return ParseSplitArguments(parsedArgs);
17+
}
1518

16-
var parsedArgs = Parse(cmdLineString);
19+
public static ParsedCommands ParseUntrustedCommands(string[] cmdLineStrings)
20+
{
21+
var parsedArgs = Parse(cmdLineStrings);
22+
return ParseSplitArguments(parsedArgs);
23+
}
24+
25+
private static ParsedCommands ParseSplitArguments(List<KeyValuePair<string, string>> parsedArgs)
26+
{
27+
var commands = new ParsedCommands();
1728

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

3041
default:
31-
command.Type = ParsedCommandType.Unkwon;
42+
//case "-Cmdless":
43+
try
44+
{
45+
if (kvp.Value.StartsWith("::{") || kvp.Value.StartsWith("shell:"))
46+
command.Type = ParsedCommandType.ExplorerShellCommand;
47+
else if (Path.IsPathRooted(kvp.Value))
48+
command.Type = ParsedCommandType.OpenPath;
49+
else
50+
command.Type = ParsedCommandType.Unknown;
51+
}
52+
catch (Exception ex)
53+
{
54+
Debug.WriteLine($"Exception in CommandLineParser.cs\\ParseUntrustedCommands with message: {ex.Message}");
55+
command.Type = ParsedCommandType.Unknown;
56+
}
3257
break;
3358
}
3459

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

42-
public static List<KeyValuePair<string, string>> Parse(string argString = null)
67+
static string[] SplitArguments(string commandLine)
4368
{
44-
var parsedArgs = new List<KeyValuePair<string, string>>();
69+
char[] commandLineCharArray = commandLine.ToCharArray();
70+
bool isInQuote = false;
4571

46-
string[] args = argString.Split(" ");
72+
for (int i = 0; i < commandLineCharArray.Length; i++)
73+
{
74+
if (commandLineCharArray[i] == '"')
75+
isInQuote = !isInQuote;
76+
77+
if (!isInQuote && commandLineCharArray[i] == ' ')
78+
commandLineCharArray[i] = '\n';
79+
}
80+
81+
return new string(commandLineCharArray).Replace("\"", "").Split('\n');
82+
}
83+
84+
public static List<KeyValuePair<string, string>> Parse(string[] args = null)
85+
{
86+
var parsedArgs = new List<KeyValuePair<string, string>>();
87+
//Environment.GetCommandLineArgs() IS better but... I haven't tested this enough.
4788

4889
if (args != null)
4990
{
50-
for (int i = 0; i < args.Length; i++)
91+
//if - or / are not used then add the command as-is
92+
93+
if (args.Length > 2)
5194
{
52-
if (args[i].StartsWith("-") || args[i].StartsWith("/"))
95+
for (int i = 0; i < args.Length; i++)
5396
{
54-
var data = ParseData(args, i);
55-
56-
if (data.Key != null)
97+
if (args[i].StartsWith("-") || args[i].StartsWith("/"))
5798
{
58-
for (int j = 0; j < parsedArgs.Count; j++)
99+
var data = ParseData(args, i);
100+
101+
if (data.Key != null)
59102
{
60-
if (parsedArgs[j].Key == data.Key)
103+
for (int j = 0; j < parsedArgs.Count; j++)
61104
{
62-
parsedArgs.RemoveAt(j);
105+
if (parsedArgs[j].Key == data.Key)
106+
{
107+
parsedArgs.RemoveAt(j);
108+
}
63109
}
64-
}
65110

66-
parsedArgs.Add(data);
111+
parsedArgs.Add(data);
112+
}
67113
}
68114
}
69115
}
70116
}
71117

118+
if (parsedArgs.Count == 0 && args.Length >= 2)
119+
parsedArgs.Add(new KeyValuePair<string, string>("-Cmdless", string.Join(" ", args.Skip(1))));
120+
72121
return parsedArgs;
73122
}
74123

0 commit comments

Comments
 (0)