Jamie Reece Wilson
7046ccec11
[+] Added new shell dirs API [+] AuOptional<AuROString> GetUserDocuments() [+] AuOptional<AuROString> GetUserDownloads() [+] AuOptional<AuROString> GetUserDesktop() [+] AuOptional<AuROString> GetUserPhotos() [+] AuOptional<AuROString> GetUserVideos() [+] AuOptional<AuROString> GetUserMusic() [*] Amend IPCHandle::InitFromSharing (use string view) [*] AuFS devices API should now use string views [*] AuProcess, Process APIs now use string views (ModuleLoadRequest, LoadModule, GetProcAddressEx, etc) [*] AuProcess, Paths APIs now use string views (GetProcessDirectory, GetProcessFullPath, etc) [*] Fix XP using common my documents vs local user documents
120 lines
3.0 KiB
C++
120 lines
3.0 KiB
C++
/***
|
|
Copyright (C) 2023 Jamie Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: FSPlatformDevices.cpp
|
|
Date: 2023-08-11
|
|
Date: 2023-12-05
|
|
Author: Reece
|
|
***/
|
|
#include <Source/RuntimeInternal.hpp>
|
|
#include "FS.hpp"
|
|
#include "FSPlatformDevices.hpp"
|
|
|
|
namespace Aurora::IO::FS
|
|
{
|
|
void InitPlatformFSCacheAtLoad()
|
|
{
|
|
static AuInitOnce gInitOnce;
|
|
|
|
gInitOnce.Call([]()
|
|
{
|
|
ResetDeviceCache();
|
|
});
|
|
}
|
|
|
|
AUKN_SYM AuResult<AuString> GetDeviceModel(const AuROString &physicalDevicePath)
|
|
{
|
|
InitPlatformFSCacheAtLoad();
|
|
|
|
AU_LOCK_GLOBAL_GUARD(gFSDirMutex);
|
|
for (const auto &refFSDevice : gCachedDevices)
|
|
{
|
|
if (refFSDevice.devicePath == physicalDevicePath)
|
|
{
|
|
auto copy = refFSDevice.productModel;
|
|
return AuMove(copy);
|
|
}
|
|
}
|
|
|
|
return {};
|
|
}
|
|
|
|
AUKN_SYM AuResult<FSDevice> GetFSDeviceByFilePath(const AuROString &path)
|
|
{
|
|
AuPair<AuUInt, const FSDevice *> lastDev =
|
|
AuMakePair<AuUInt, const FSDevice *>(0, nullptr);
|
|
|
|
InitPlatformFSCacheAtLoad();
|
|
|
|
auto normalized = AuFS::NormalizePathRet(path);
|
|
if (normalized.empty())
|
|
{
|
|
return {};
|
|
}
|
|
|
|
AU_LOCK_GLOBAL_GUARD(gFSDirMutex);
|
|
|
|
for (const auto &refFSDevice : gCachedDevices)
|
|
{
|
|
for (const auto &refPart : refFSDevice.partitions)
|
|
{
|
|
for (const auto &refMnt : refPart.filesystemMountPoints)
|
|
{
|
|
if (AuStartsWith(path, refMnt))
|
|
{
|
|
if (AuGet<0>(lastDev) < refMnt.size())
|
|
{
|
|
lastDev = AuMakePair(refMnt.size(), &refFSDevice);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (AuGet<0>(lastDev) == 0)
|
|
{
|
|
return {};
|
|
}
|
|
|
|
auto copy = *AuGet<1>(lastDev);
|
|
return AuMove(copy);
|
|
}
|
|
|
|
AUKN_SYM AuList<FSDevice> GetFSDevices()
|
|
{
|
|
InitPlatformFSCacheAtLoad();
|
|
AU_LOCK_GLOBAL_GUARD(gFSDirMutex);
|
|
return gCachedDevices;
|
|
}
|
|
|
|
AUKN_SYM AuResult<FSDevice> GetFSDeviceByDevice(const AuROString &physicalDevicePath)
|
|
{
|
|
InitPlatformFSCacheAtLoad();
|
|
|
|
AU_LOCK_GLOBAL_GUARD(gFSDirMutex);
|
|
for (const auto &refFSDevice : gCachedDevices)
|
|
{
|
|
if (refFSDevice.devicePath == physicalDevicePath)
|
|
{
|
|
auto copy = refFSDevice;
|
|
return AuMove(copy);
|
|
}
|
|
}
|
|
|
|
return {};
|
|
}
|
|
|
|
AUKN_SYM const AuList<FSDevice> &GetFSDevicesCachedUnsafe()
|
|
{
|
|
InitPlatformFSCacheAtLoad();
|
|
return gCachedDevices;
|
|
}
|
|
|
|
AuList<FSDevice> SysGetFSDevices();
|
|
|
|
AUKN_SYM void ResetDeviceCache()
|
|
{
|
|
AU_LOCK_GLOBAL_GUARD(gFSDirMutex);
|
|
gCachedDevices = AuMove(SysGetFSDevices());
|
|
}
|
|
} |