Skip to content

Offline devices in windows mess up places #204

Open
@jvannugteren

Description

@jvannugteren

When a device is not available in windows, for example a network drive is offline, it still shows up in filedialog places. But when the user tries to open the non-existing drive weird things happen. The path reverts to the default, but the files shown are likely from the first bookmark. I think the way to avoid this all together is by modifying the following function:

std::vector<IGFD::PathDisplayedName> GetDevicesList() override {
        std::vector<IGFD::PathDisplayedName> res;
#ifdef _IGFD_WIN_
        const DWORD mydrives = 2048;
        char lpBuffer[2048];
#define mini(a, b) (((a) < (b)) ? (a) : (b))
        const DWORD countChars = mini(GetLogicalDriveStringsA(mydrives, lpBuffer), 2047);
#undef mini
        if (countChars > 0U && countChars < 2049U) {
            std::string var = std::string(lpBuffer, (size_t)countChars);
            IGFD::Utils::ReplaceString(var, "\\", "");
            auto arr = IGFD::Utils::SplitStringToVector(var, '\0', false);
            wchar_t szVolumeName[2048];
            IGFD::PathDisplayedName path_name;
            for (auto& a : arr) {
                path_name.first = a;
                path_name.second.clear();
                // std::wstring wpath = IGFD::Utils::UTF8Decode(a);

                std::wstring wpath = IGFD::Utils::UTF8Decode(a) + L"\\"; // otherwise can't even find C drive
                if (GetVolumeInformationW(wpath.c_str(), szVolumeName, 2048, NULL, NULL, NULL, NULL, 0)) {
                    path_name.second = IGFD::Utils::UTF8Encode(szVolumeName);
                    res.push_back(path_name);
                }
            }
        }
#endif  // _IGFD_WIN_
        return res;
    }

When GetVolumeInformationW fails, for example because the drive is not available, it will not add the path to the list. Also I ran into an issue where the C drive did not show up due to a missing \ somehow. The only problem left is now that if the drive goes offline after the filedialog instance has been created. Not sure how to fix this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions