Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
maxima120 committed Oct 19, 2021
1 parent 14f037d commit c18ef12
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 105 deletions.
110 changes: 7 additions & 103 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private void ProcessSettings(UserSettings settings)
settings.Items.Add(CreateItem(link, windows));
}

Trace.WriteLine($"Init links processed in: {sw.Elapsed}");
Trace.WriteLine($"PMT. Init links processed in: {sw.Elapsed}");

this.DataContext = settings;
}
Expand Down Expand Up @@ -288,13 +288,12 @@ private void lst_MouseDoubleClick(object sender, MouseButtonEventArgs e)

try
{
// TODO : see if more needs to be done to avoid any dependency between this process and the children.
Process.Start(new ProcessStartInfo { FileName = item.LnkPath, UseShellExecute = true });
RefreshItemWindowsAsync(item);
}
catch (Exception ex)
{
Trace.WriteLine($"Process start exception: {ex}");
Trace.WriteLine($"PMT. Process start exception: {ex}");
SystemSounds.Exclamation.Play();
}

Expand Down Expand Up @@ -335,9 +334,9 @@ private void UnpinMenuItem_Click(object sender, RoutedEventArgs e)

lst.Items.Remove(item);
}
catch (Exception)
catch (Exception ex)
{
// TODO
Trace.WriteLine($"PMT. Unpin exception: {ex}");
SystemSounds.Exclamation.Play();
}
}
Expand Down Expand Up @@ -378,7 +377,7 @@ private List<LinkWindow> GetItemWindows(LinkItem item, List<IntPtr> windows = nu
if (processes == null || processes.Length == 0)
return result;

// TODO: can you make it faster? (init links runs for 180ms and individual links for 5-45ms)
// TODO: can you make it faster? (init links runs for 140ms and individual links for 5-50ms)

if (windows == null)
windows = PInvoker.GetTaskBarWindows();
Expand All @@ -391,7 +390,7 @@ private List<LinkWindow> GetItemWindows(LinkItem item, List<IntPtr> windows = nu
{
// TODO: this presumably filters out similar processes started from another source (not LNK)
// but not sure I need it
if (item.LnkTarget == process.MainModule?.FileName)
//if (item.LnkTarget == process.MainModule?.FileName)
{
foreach (var w in wp.Where(i => i.Value == process.Id))
{
Expand Down Expand Up @@ -493,7 +492,7 @@ private void RefreshItemWindows(LinkItem item, bool showPopup, List<IntPtr> wind
}

sw.Stop();
Debug.WriteLine("Refresh Item: {0}", sw.Elapsed);
Debug.WriteLine($"Refresh Item: {sw.Elapsed}");
}

private void WindowRestoreButton_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -523,98 +522,3 @@ private void WindowCloseButton_Click(object sender, RoutedEventArgs e)
#endregion
}
}

// NB: needs to be run as administrator to get the properties
// Apparently drag drop stops working if ran as administrator.. pfff

//var sh = new Shell32.Shell();
//var folder = sh.NameSpace(Path.GetDirectoryName(filename));
//var folderItem = folder.Items().Item(Path.GetFileName(filename));
//var link = (Shell32.ShellLinkObject)folderItem.GetLink;


// NB: WMI timing is x10 of the .NET GetProcesses

// TODO : try select with WHERE and specific names
//var queryString = @"SELECT Name, ProcessId, ExecutablePath FROM Win32_Process WHERE ExecutablePath = 'C:\Users\Public\Desktop\TablePlus.lnk'";

//var searcher = new ManagementObjectSearcher(@"\\.\root\CIMV2", queryString);
//var processes = searcher.Get();

//foreach (var process in processes)
//{
// var name = process["Name"].ToString();
// var processId = Convert.ToInt32(process["ProcessId"]);
// var executablePath = process["ExecutablePath"]?.ToString() ?? "";

// var item = settings.items.SingleOrDefault(i => i.lnkTarget == executablePath);

// if (item == null)
// continue;

// Debug.WriteLine(" process {0} for link {1} is running.", processId, item.lnkPath);
//}

//Debug.WriteLine("Processed in: {0}", sw.Elapsed);

//sw.Restart();
//Process[] pps = Process.GetProcesses();

// NB: without stopwords - there are exceptions which make it run for 500-600ms instead of 10ms
//var stopWords = new[] {
// "Idle",
// "System",
// "Registry",
// "smss",
// "csrss",
// "wininit",
// "csrss",
// "services",
// "Memory Compression",
// "MBAMService",
// "svchost",
// "SecurityHealthService",
// "SgrmBroker",
// "svchost"
//};

//foreach (var process in pps)
//{
// //Debug.WriteLine("{0}:{1}", process.Id, process.ProcessName);

// //if (stopWords.Contains(process.ProcessName))
// // continue;

// string module = null;
// try
// {
// module = process.MainModule?.FileName;
// }
// catch (Win32Exception ex)
// {
// errors++;
// Debug.WriteLine("Win32Exception {0}:{1}", process.Id, process.ProcessName);
// continue;
// }
// catch (InvalidOperationException)
// {
// errors++;
// Debug.WriteLine("InvalidOperationException {0}:{1}", process.Id, process.ProcessName);
// continue;
// }
// catch (Exception)
// {
// errors++;
// Debug.WriteLine("Exception {0}:{1}", process.Id, process.ProcessName);
// continue;
// }

// // TODO : index by target and PID
// var item = settings.items.SingleOrDefault(i => i.lnkTarget == module);

// if (item == null)
// continue;

// Debug.WriteLine(" process {0} for link {1} is running.", process.Id, item.lnkPath);
//}

2 changes: 1 addition & 1 deletion PMTaskbar.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<Version>1.1.2.2</Version>
<Version>1.1.2.3</Version>
<UseWPF>true</UseWPF>
<ApplicationIcon>icon.ico</ApplicationIcon>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion SettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace PMTaskbar
public SettingsManager(string fileName)
{
filePath = GetLocalFilePath(fileName);
Trace.WriteLine(filePath);
Trace.WriteLine($"PMT. Settings: {filePath}");
}

private string GetLocalFilePath(string fileName)
Expand Down

0 comments on commit c18ef12

Please sign in to comment.