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

Support UNC path capacity on Windows #22202

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

DoubleSpicy
Copy link
Contributor

@DoubleSpicy DoubleSpicy commented Jan 24, 2025

Add UNC path capacity calculation capability by invoking Windows API directly.

For #21954,
Can we get a confirmation on linux as well?

@DoubleSpicy
Copy link
Contributor Author

QT seems doesn't have full support of UNC paths in general, a workaround is to mount it as a drive, mentioned at PCSX2/pcsx2#6258 and https://forum.qt.io/topic/96418/how-to-create-a-folder-and-write-a-file-in-it-using-the-unc-path/2

@glassez glassez changed the title Support UNC path capacity on windows Support UNC path capacity on Windows Jan 25, 2025
@@ -99,6 +104,27 @@ namespace
Path current = path;
qint64 freeSpace = Utils::Fs::freeDiskSpaceOnPath(current);

// UNC path support on windows
Copy link
Member

Choose a reason for hiding this comment

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

It should be done inside Utils::Fs::freeDiskSpaceOnPath().

@@ -99,6 +104,27 @@ namespace
Path current = path;
qint64 freeSpace = Utils::Fs::freeDiskSpaceOnPath(current);

// UNC path support on windows
#ifdef Q_OS_WIN
if (freeSpace < 0 && PathIsUNC(current.data().toStdWString().c_str()))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (freeSpace < 0 && PathIsUNC(current.data().toStdWString().c_str()))
if ((freeSpace < 0) && PathIsUNCW(current.data().toStdWString().c_str()))

Comment on lines +111 to +113
ULARGE_INTEGER FreeBytesAvailable = { 0 };
ULARGE_INTEGER TotalNumberOfBytes = { 0 };
ULARGE_INTEGER TotalNumberOfFreeBytes = { 0 };
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
ULARGE_INTEGER FreeBytesAvailable = { 0 };
ULARGE_INTEGER TotalNumberOfBytes = { 0 };
ULARGE_INTEGER TotalNumberOfFreeBytes = { 0 };
ULARGE_INTEGER freeBytesAvailable = {0};
ULARGE_INTEGER totalNumberOfBytes = {0};
ULARGE_INTEGER totalNumberOfFreeBytes = {0};

Copy link
Member

Choose a reason for hiding this comment

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

IIRC, both totalNumberOfBytes and totalNumberOfFreeBytes are redundant (unused) and can be omitted.

Comment on lines +114 to +119
BOOL ok = GetDiskFreeSpaceEx(
current.data().toStdWString().c_str(),
&FreeBytesAvailable,
&TotalNumberOfBytes,
&TotalNumberOfFreeBytes
);
Copy link
Member

Choose a reason for hiding this comment

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

Such indentation is too overkill.

Suggested change
BOOL ok = GetDiskFreeSpaceEx(
current.data().toStdWString().c_str(),
&FreeBytesAvailable,
&TotalNumberOfBytes,
&TotalNumberOfFreeBytes
);
const BOOL ok = GetDiskFreeSpaceExW(current.data().toStdWString().c_str()
, &freeBytesAvailable, &totalNumberOfBytes, &totalNumberOfFreeBytes);

Comment on lines +121 to +124
if (ok)
{
freeSpace = FreeBytesAvailable.QuadPart;
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (ok)
{
freeSpace = FreeBytesAvailable.QuadPart;
}
if (ok)
freeSpace = freeBytesAvailable.QuadPart;

freeSpace = FreeBytesAvailable.QuadPart;
}
}
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#endif
#endif

@@ -99,6 +104,27 @@ namespace
Path current = path;
qint64 freeSpace = Utils::Fs::freeDiskSpaceOnPath(current);

// UNC path support on windows
#ifdef Q_OS_WIN
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#ifdef Q_OS_WIN
#ifdef Q_OS_WIN

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants