Skip to content

When creating explorer favorite use more specific windows functions - #5690

Merged
jturcotte merged 8 commits into
owncloud:masterfrom
remixtj:utility_SHGetKnownFolderPath
Apr 27, 2017
Merged

jturcotte merged 8 commits into
owncloud:masterfrom
remixtj:utility_SHGetKnownFolderPath

Conversation

@remixtj

@remixtj remixtj commented Apr 10, 2017

Copy link
Copy Markdown
Contributor

Fixes #2719

@CLAassistant

CLAassistant commented Apr 10, 2017 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@guruz
guruz requested a review from jturcotte April 10, 2017 13:04
@guruz guruz added this to the 2.4.0 milestone Apr 10, 2017
Comment thread src/libsync/utility_win.cpp Outdated
QLibrary kernel32Lib("shell32.dll");
if(kernel32Lib.load())
{
SHGetKnownFolderPathPtr = (SHGetKnownFolderPathFun) kernel32Lib.resolve("SHGetKnownFolderPath");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This function seems to be supported since Windows Vista, but we require Windows 7 at least. Would it be possible to use normal dynamic linking to access it rather than doing a manual symbol lookup?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Last time i tried this i had errors with direct lookup, but maybe because was testing also XP clients. If you say that Windows 7 is the minimum supported, i can try rewriting it

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@remixtj I'd be great if you could try rewriting to use normal dynamic linking. Feel free to ping me if you need someone to test on Win7.

@jturcotte jturcotte left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for the cleanup, looks already much simpler. Just one more thing.


/* Use new WINAPI functions */
wchar_t *path = NULL;
if(SHGetKnownFolderPath(FOLDERID_Links, 0, NULL, &path) == S_OK) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

From the documentation about the path argument:

The calling process is responsible for freeing this resource once it is no longer needed by calling CoTaskMemFree.

Could you verify or fix it?

Comment thread src/libsync/utility_win.cpp Outdated
linkName = QDir(links).filePath(folderDir.dirName() + QLatin1String(".lnk"));
}
qDebug() << Q_FUNC_INFO << " creating link from " << linkName << " to " << folder;
CoTaskMemFree(path);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This will crash if path is not null and yet not pointing to a valid allocation, which can happen if SHGetKnownFolderPath doesn't touch it. You could either move CoTaskMemFree into the if(){}, or initialize path to NULL.

@jturcotte jturcotte left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great, thank you :)

@jturcotte

jturcotte commented Apr 26, 2017 •

Copy link
Copy Markdown
Contributor

Argh...

/var/lib/jenkins/workspace/cloud-client_client_PR-5690-ICN3YAYSR6SITVLPHS5TYBHNKKE7PAVK3ABYGFA5SQ67JL2DZEJA/src/libsync/utility_win.cpp:36:59: error: 'SHGetKnownFolderPath' was not declared in this scope

The CI (and our build servers) might not be able to cross-build this... Are you testing your patch on Windows with MinGW, or are you using MSVC?

@guruz guruz added the ReadyToTest QA, please validate the fix/enhancement label Apr 26, 2017
@remixtj

remixtj commented Apr 27, 2017

Copy link
Copy Markdown
Contributor Author

Hi,

i'm compiling on mingw32-w64 on opensuse.

Maybe my environment is not much up to date, but works.

@jturcotte

Copy link
Copy Markdown
Contributor

That's perfect then, that's our official toolchain. Thanks for the patch and for fixing the build, I'll merge it 👍

@jturcotte
jturcotte merged commit 3db8d3d into owncloud:master Apr 27, 2017
@remixtj
remixtj deleted the utility_SHGetKnownFolderPath branch April 27, 2017 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ReadyToTest QA, please validate the fix/enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants