Skip to content

Commit

Permalink
- Closes BE-530 - fixed problem with command line parameters and thei…
Browse files Browse the repository at this point in the history
…r parsing
  • Loading branch information
DimitarCC committed Dec 1, 2016
1 parent d998335 commit 2f69144
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 106 deletions.
38 changes: 9 additions & 29 deletions BExplorer/BetterExplorer/App.xaml.cs
Expand Up @@ -146,7 +146,7 @@ public partial class App : Application {

//// loads current Ribbon color theme
try {
var Color = Convert.ToString(rks.GetValue("CurrentTheme", "Blue"));
var color = Convert.ToString(rks.GetValue("CurrentTheme", "Blue"));
var owner = Application.Current.MainWindow;
if (owner != null) {
owner.Resources.BeginInit();
Expand All @@ -155,41 +155,31 @@ public partial class App : Application {
owner.Resources.MergedDictionaries.RemoveAt(0);
}

if (string.IsNullOrEmpty(Color) == false) {
owner.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri(Color) });
if (string.IsNullOrEmpty(color) == false) {
owner.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri(color) });
}

owner.Resources.EndInit();
}
Application.Current.Resources.BeginInit();

Application.Current.Resources.MergedDictionaries.RemoveAt(1);

switch (Color) {
switch (color) {
case "Blue":
case "Silver":
case "Black":
case "Green":
Application.Current.Resources.MergedDictionaries.Insert(1, new ResourceDictionary() { Source = new Uri($"pack://application:,,,/Fluent;component/Themes/Office2010/{Color}.xaml") });
Application.Current.Resources.MergedDictionaries.Insert(1, new ResourceDictionary() { Source = new Uri($"pack://application:,,,/Fluent;component/Themes/Office2010/{color}.xaml") });
break;
case "Metro":
Application.Current.Resources.MergedDictionaries.Insert(1, new ResourceDictionary() { Source = new Uri("pack://application:,,,/Fluent;component/Themes/Office2013/Generic.xaml") });
break;
default:
Application.Current.Resources.MergedDictionaries.Insert(1, new ResourceDictionary() { Source = new Uri($"pack://application:,,,/Fluent;component/Themes/Office2010/{Color}.xaml") });
Application.Current.Resources.MergedDictionaries.Insert(1, new ResourceDictionary() { Source = new Uri($"pack://application:,,,/Fluent;component/Themes/Office2010/{color}.xaml") });
break;
}
Application.Current.Resources.EndInit();

if (owner is RibbonWindow) {
owner.Style = null;
owner.Style = owner.FindResource("RibbonWindowStyle") as Style;
owner.Style = null;

// Resize Window to work around alignment issues caused by theme change
++owner.Width;
--owner.Width;
}
} catch (Exception ex) {
//MessageBox.Show(String.Format("An error occurred while trying to load the theme data from the Registry. \n\r \n\r{0}\n\r \n\rPlease let us know of this issue at http://bugtracker.better-explorer.com/", ex.Message), "RibbonTheme Error - " + ex.ToString());
MessageBox.Show($"An error occurred while trying to load the theme data from the Registry. \n\r \n\rRibbonTheme Error - {ex.ToString()}\n\r \n\rPlease let us know of this issue at http://bugtracker.better-explorer.com/", ex.Message);
Expand All @@ -208,7 +198,7 @@ public partial class App : Application {
IsStartMinimized = true;
}

if (dmi && !ApplicationInstanceManager.CreateSingleInstance(Assembly.GetExecutingAssembly().GetName().Name, SingleInstanceCallback))
if (!ApplicationInstanceManager.CreateSingleInstance(Assembly.GetExecutingAssembly().GetName().Name, SingleInstanceCallback) && dmi)
return; // exit, if same app. is running

base.OnStartup(e);
Expand Down Expand Up @@ -255,10 +245,6 @@ public partial class App : Application {
if (args?.CommandLineArgs == null || !args.CommandLineArgs.Any()) return;
if (args.CommandLineArgs.Length == 1) {
win.Visibility = Visibility.Visible;
//if (win.WindowState == WindowState.Minimized) {
// User32.ShowWindow((PresentationSource.FromVisual(win) as HwndSource).Handle, User32.ShowWindowCommands.Restore);
//}
//User32.ForceForegroundWindow(win);
windowsActivate.ActivateForm(win, null, IntPtr.Zero);
} else {
if (args.CommandLineArgs[1] == "/nw") {
Expand All @@ -267,9 +253,6 @@ public partial class App : Application {
IListItemEx sho = null;
if (args.CommandLineArgs[1] == "t") {
win.Visibility = Visibility.Visible;
//if (win.WindowState == WindowState.Minimized)
// User32.ShowWindow((PresentationSource.FromVisual(win) as HwndSource).Handle,
// User32.ShowWindowCommands.Restore);
windowsActivate.ActivateForm(win, null, IntPtr.Zero);
sho = FileSystemListItem.ToFileSystemItem(IntPtr.Zero, startUpLocation.ToShellParsingName());
Expand All @@ -294,20 +277,17 @@ public partial class App : Application {
CreateInitialTab(win, sho);
}
}
//User32.ForceForegroundWindow(win);
windowsActivate.ActivateForm(win, null, IntPtr.Zero);
}
};
Dispatcher.BeginInvoke(d, true);
}

private void Win_StateChanged(object sender, EventArgs e) {
if ((sender as Window).WindowState != WindowState.Minimized) {
if ((sender as Window)?.WindowState != WindowState.Minimized) {
(sender as Window).Visibility = Visibility.Visible;
CombinedWindowActivator windowsActivate = new CombinedWindowActivator();
windowsActivate.ActivateForm(sender as Window, null, IntPtr.Zero);
//User32.ForceForegroundWindow(sender as Window);
}
}

Expand Down
19 changes: 11 additions & 8 deletions BExplorer/BetterExplorer/MainWindow.xaml.cs
Expand Up @@ -925,10 +925,10 @@ public partial class MainWindow : Fluent.RibbonWindow {
(Action)(() => {
this.beNotifyIcon.ShowBalloonTip("Information", $"It is safe to remove {item.LogicalDrive}", Hardcodet.Wpf.TaskbarNotification.BalloonIcon.Info);
var tabsForRemove = tcMain.Items.OfType<Wpf.Controls.TabItem>().Where(w => {
var root = String.Empty;
try {
root = Path.GetPathRoot(w.ShellObject.ParsingName.ToShellParsingName());
} catch {}
var root = String.Empty;
try {
root = Path.GetPathRoot(w.ShellObject.ParsingName.ToShellParsingName());
} catch { }
return !String.IsNullOrEmpty(root) && (w.ShellObject.IsFileSystem &&
root.ToLowerInvariant() == $"{DriveLetter}:\\".ToLowerInvariant());
}).ToArray();
Expand Down Expand Up @@ -1670,8 +1670,11 @@ public partial class MainWindow : Fluent.RibbonWindow {
tcMain_Setup(null, null);
//'set StartUp location
if (Application.Current.Properties["cmd"] != null && Application.Current.Properties["cmd"].ToString() != "-minimized") {
//if (Application.Current.Properties["cmd"].ToString() == "/nw")
//tcMain.NewTab(ShellListView.CurrentFolder, true);
var cmd = Application.Current.Properties["cmd"].ToString();
if (cmd != "/nw" && cmd != "/t") {
var sho = FileSystemListItem.ToFileSystemItem(this._ShellListView.LVHandle, cmd.ToShellParsingName());
tcMain.NewTab(sho, true);
}
} else {
InitializeInitialTabs();
}
Expand Down Expand Up @@ -3511,7 +3514,7 @@ public partial class MainWindow : Fluent.RibbonWindow {
} else {
var realItem = this._ShellListView.Items.ToArray().FirstOrDefault(w => w.GetUniqueID() == oldCurrentItem.GetUniqueID());
if (realItem != null) {
this._ShellListView.SelectItems(new[] {realItem});
this._ShellListView.SelectItems(new[] { realItem });
} else {
if (!curentFolder.ParsingName.Contains(oldCurrentItem.ParsingName)) {
var parents = new List<IListItemEx>();
Expand All @@ -3520,7 +3523,7 @@ public partial class MainWindow : Fluent.RibbonWindow {
parents.Add(parent);
realItem = this._ShellListView.Items.ToArray().FirstOrDefault(w => w.GetUniqueID() == parent.GetUniqueID());
if (realItem != null) {
this._ShellListView.SelectItems(new[] {realItem});
this._ShellListView.SelectItems(new[] { realItem });
break;
}
parent = parent.Parent;
Expand Down
140 changes: 71 additions & 69 deletions Shell/ShellViewEx.cs
Expand Up @@ -3098,76 +3098,7 @@ public partial class ShellView : UserControl {
}
}

if (destination.IsFileSystem) {
if (this._FsWatcher != null) {
this.BeginInvoke((MethodInvoker) (() => this._FsWatcher.Dispose()));
this._FsWatcher = new FileSystemWatcher(@destination.ParsingName);
//this._FsWatcher.InternalBufferSize = 64 * 1024 * 1024;
this._FsWatcher.Changed += (sender, args) => {
try {
var objUpdateItem = FileSystemListItem.ToFileSystemItem(this.LVHandle, args.FullPath);
if (this.CurrentFolder != null && objUpdateItem.Parent != null && objUpdateItem.Parent.Equals(this.CurrentFolder)) {
var exisitingUItem = this.Items.ToArray().FirstOrDefault(w => w.Equals(objUpdateItem));
if (exisitingUItem != null)
this.RefreshItem(exisitingUItem.ItemIndex, true);
if (this.RequestedCurrentLocation != null && objUpdateItem.Equals(this.RequestedCurrentLocation))
this.UnvalidateDirectory();
}
} catch (FileNotFoundException) {
//Probably a temporary file
this._TemporaryFiles.Add(args.FullPath);
} catch {
}
};
this._FsWatcher.Error += (sender, args) => {
var ex = args.GetException();
};
this._FsWatcher.Created += (sender, args) => {
try {
//var existing = this.Items.FirstOrDefault(s => s.ParsingName.Equals(args.FullPath));
//if (existing != null) return;
if (Path.GetExtension(args.FullPath).ToLowerInvariant() == ".tmp" ||
Path.GetExtension(args.FullPath) == String.Empty) {
if (!this._TemporaryFiles.Contains(args.FullPath))
this._TemporaryFiles.Add(args.FullPath);
}
var obj = FileSystemListItem.ToFileSystemItem(this.LVHandle, args.FullPath);
if (this.CurrentFolder != null && (obj.Parent != null && obj.Parent.Equals(this.CurrentFolder))) {
if (this.IsRenameNeeded) {
var existingItem = this.Items.ToArray().FirstOrDefault(s => s.Equals(obj));
if (existingItem == null) {
var itemIndex = this.InsertNewItem(obj);
this.SelectItemByIndex(itemIndex, true, true);
this.RenameSelectedItem(itemIndex);
this.IsRenameNeeded = false;
} else {
this.RenameSelectedItem(existingItem.ItemIndex);
}
} else {
if (this._ItemsQueue.Enqueue(new Tuple<ItemUpdateType, IListItemEx>(ItemUpdateType.Created, obj)))
this.UnvalidateDirectory();
}
}
} catch (FileNotFoundException) {
this.QueueDeleteItem(args);
} catch { }
};
this._FsWatcher.Deleted += (sender, args) => {
//args.FullPath
this.QueueDeleteItem(args);
};
this._FsWatcher.Renamed += (sender, args) => {
};

this._FsWatcher.IncludeSubdirectories = false;
this._FsWatcher.NotifyFilter = NotifyFilters.CreationTime | NotifyFilters.DirectoryName | NotifyFilters.Attributes |
NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.Security |
NotifyFilters.Size;
}

this._FsWatcher.EnableRaisingEvents = true;
}

this._UnvalidateTimer.Stop();
this._IsDisplayEmptyText = false;
Expand Down Expand Up @@ -3247,6 +3178,77 @@ public partial class ShellView : UserControl {

var navigationThread = new Thread(() => {
destination = FileSystemListItem.ToFileSystemItem(destination.ParentHandle, destination.PIDL);
if (destination.IsFileSystem) {
if (this._FsWatcher != null) {
this._FsWatcher.EnableRaisingEvents = false;
this._FsWatcher.Dispose();
this._FsWatcher = new FileSystemWatcher(@destination.ParsingName);
//this._FsWatcher.InternalBufferSize = 64 * 1024 * 1024;
this._FsWatcher.Changed += (sender, args) => {
try {
var objUpdateItem = FileSystemListItem.ToFileSystemItem(this.LVHandle, args.FullPath);
if (this.CurrentFolder != null && objUpdateItem.Parent != null && objUpdateItem.Parent.Equals(this.CurrentFolder)) {
var exisitingUItem = this.Items.ToArray().FirstOrDefault(w => w.Equals(objUpdateItem));
if (exisitingUItem != null)
this.RefreshItem(exisitingUItem.ItemIndex, true);
if (this.RequestedCurrentLocation != null && objUpdateItem.Equals(this.RequestedCurrentLocation))
this.UnvalidateDirectory();
}
} catch (FileNotFoundException) {
//Probably a temporary file
this._TemporaryFiles.Add(args.FullPath);
} catch {
}
};
this._FsWatcher.Error += (sender, args) => {
var ex = args.GetException();
};
this._FsWatcher.Created += (sender, args) => {
try {
//var existing = this.Items.FirstOrDefault(s => s.ParsingName.Equals(args.FullPath));
//if (existing != null) return;
if (Path.GetExtension(args.FullPath).ToLowerInvariant() == ".tmp" ||
Path.GetExtension(args.FullPath) == String.Empty) {
if (!this._TemporaryFiles.Contains(args.FullPath))
this._TemporaryFiles.Add(args.FullPath);
}
var obj = FileSystemListItem.ToFileSystemItem(this.LVHandle, args.FullPath);
if (this.CurrentFolder != null && (obj.Parent != null && obj.Parent.Equals(this.CurrentFolder))) {
if (this.IsRenameNeeded) {
var existingItem = this.Items.ToArray().FirstOrDefault(s => s.Equals(obj));
if (existingItem == null) {
var itemIndex = this.InsertNewItem(obj);
this.SelectItemByIndex(itemIndex, true, true);
this.RenameSelectedItem(itemIndex);
this.IsRenameNeeded = false;
} else {
this.RenameSelectedItem(existingItem.ItemIndex);
}
} else {
if (this._ItemsQueue.Enqueue(new Tuple<ItemUpdateType, IListItemEx>(ItemUpdateType.Created, obj)))
this.UnvalidateDirectory();
}
}
} catch (FileNotFoundException) {
this.QueueDeleteItem(args);
} catch { }
};
this._FsWatcher.Deleted += (sender, args) => {
//args.FullPath
this.QueueDeleteItem(args);
};
this._FsWatcher.Renamed += (sender, args) => {
};
this._FsWatcher.IncludeSubdirectories = false;
this._FsWatcher.NotifyFilter = NotifyFilters.CreationTime | NotifyFilters.DirectoryName | NotifyFilters.Attributes |
NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.Security |
NotifyFilters.Size;
}
this._FsWatcher.EnableRaisingEvents = true;
}
this.RequestedCurrentLocation = destination;
var column = columns ?? this.AllAvailableColumns.Single(s => s.Value.ID == "A0").Value;
Expand Down

0 comments on commit 2f69144

Please sign in to comment.