Skip to content
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

Fix for File explorer not showing up and multiple notepads #3969

Merged
merged 9 commits into from
Jun 2, 2020

Conversation

alekhyareddy28
Copy link
Contributor

@alekhyareddy28 alekhyareddy28 commented Jun 1, 2020

Summary of the Pull Request

This PR fixes two issues, namely File Explorer not showing up and multiple notepads showing up due to multiple shortcut files in different locations.

PR Checklist

Detailed Description of the Pull Request / Additional comments

Changes made in this PR are -

  • Previously we were checking if the LnkResolvedPath is null or empty, if so we were removing that program as a duplicate. However, this was true only in case of exe's and not lnk's. Hence, added an additional check to remove only the exe applications which do not have an lnkResolvedPath. This solves the issue of applications like File Explorer not showing up because they are lnk files without a resolvedPath.
  • The check that we previously had wherein we removed apps with the same LnkResolvedPath was not sufficient because shortcuts in different locations have different lnkResolved paths (as mentioned in this comment - PowerToys run shows Notepad en Notepad++ twice #3180 (comment)). Therefore, using the condition that if two applications have the same name, same executable name and same FullPath, they are qualified as the same item.

Validation Steps Performed

image

@alekhyareddy28 alekhyareddy28 requested a review from a team June 1, 2020 17:51
@alekhyareddy28 alekhyareddy28 added the Product-PowerToys Run Improved app launch PT Run (Win+R) Window label Jun 1, 2020
@arjunbalgovind
Copy link
Contributor

Probably unrelated to the PR, but I just noticed that start menu search doesn't actually find shortcuts on the desktop. I tried creating a shortcut to an unindexed file on desktop and Start menu doesn't find it but PT Run does.

@alekhyareddy28 alekhyareddy28 changed the base branch from master to stable June 2, 2020 17:55
@alekhyareddy28 alekhyareddy28 changed the base branch from stable to master June 2, 2020 17:55

public int GetHashCode(Win32 obj)
{
return obj.FullPath.GetHashCode();
Copy link
Contributor

@dsrivastavv dsrivastavv Jun 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The equal function takes all three variables into account but hashing doesn't. So comparison using hashing and equal would produce different results.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Used exor.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think exor will ensure uniqueness for hashing. Swapping name and executable name will give false on using Equal but true on comparing hash codes because exor is commutative operation.

You can use something like below snippet which has a very low probability of being equal(which seems to be standard practice as per this post):

final int prime = 31;
int result = 1;
for( String s : strings )
{
    result = result * prime + s.hashCode();
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modified it as you suggested.

@htcfreek
Copy link
Collaborator

htcfreek commented Jun 2, 2020

What will happen if two shortcuts only difference in the start parameter for the linked app?
Is this then covered by different values in LnkResolvedPath?

@alekhyareddy28
Copy link
Contributor Author

What will happen if two shortcuts only difference in the start parameter for the linked app?
Is this then covered by different values in LnkResolvedPath?

Yes, the lnkResolved paths would be different then. The .lnk files contain information about the object that they are pointing to and also the arguments that must be passed to that object. Since they differ in their arguments, they would be different shortcuts as they do different things. Hope this clarifies your question.

Ref - https://docs.microsoft.com/en-us/windows/win32/shell/links?redirectedfrom=MSDN#link-files

Copy link
Contributor

@dsrivastavv dsrivastavv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@alekhyareddy28 alekhyareddy28 merged commit 8cddd59 into microsoft:master Jun 2, 2020
alekhyareddy28 added a commit to alekhyareddy28/PowerToys that referenced this pull request Jun 2, 2020
…#3969)

* reverted the dedup code, file explorer shows up but so do duplicates

* Fixed file explorer and dedup

* Formatting

* Added tests for all the cases

* Formatting

* Tests

* take name and exe into consideration while calculating hash

* unique primes while calculating hash code

(cherry picked from commit 8cddd59)
crutkas pushed a commit that referenced this pull request Jun 3, 2020
* Add resource only when it is not already present (#3842)

(cherry picked from commit d2dfbff)

* Take space into consideration while calculating the first matched index (#3874)

(cherry picked from commit a8d67a1)

* Fix for File explorer not showing up and multiple notepads (#3969)

* reverted the dedup code, file explorer shows up but so do duplicates

* Fixed file explorer and dedup

* Formatting

* Added tests for all the cases

* Formatting

* Tests

* take name and exe into consideration while calculating hash

* unique primes while calculating hash code

(cherry picked from commit 8cddd59)
@alekhyareddy28 alekhyareddy28 linked an issue Jun 12, 2020 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Product-PowerToys Run Improved app launch PT Run (Win+R) Window
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Powertoys-Run does not find self built and installed programs
4 participants