mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-02-06 04:00:08 +00:00
Added new method File::getFileIdentifier() for retrieving a file's unique ID.
This commit is contained in:
parent
167f75772f
commit
27046fd1a7
6 changed files with 60 additions and 10 deletions
|
|
@ -361,6 +361,14 @@ public:
|
|||
*/
|
||||
File getLinkedTarget() const;
|
||||
|
||||
/** Returns a unique identifier for the file, if one is available.
|
||||
|
||||
Depending on the OS and file-system, this may be a unix inode number or
|
||||
a win32 file identifier, or 0 if it fails to find one. The number will
|
||||
be unique on the filesystem, but not globally.
|
||||
*/
|
||||
uint64 getFileIdentifier() const;
|
||||
|
||||
//==============================================================================
|
||||
/** Returns the last modification time of this file.
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,10 @@ void MACAddress::findAllAddresses (Array<MACAddress>& result)
|
|||
&& (ifr.ifr_flags & IFF_LOOPBACK) == 0
|
||||
&& ioctl (s, SIOCGIFHWADDR, &ifr) == 0)
|
||||
{
|
||||
result.addIfNotAlreadyThere (MACAddress ((const uint8*) ifr.ifr_hwaddr.sa_data));
|
||||
MACAddress ma ((const uint8*) ifr.ifr_hwaddr.sa_data);
|
||||
|
||||
if (! ma.isNull())
|
||||
result.addIfNotAlreadyThere (ma);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,12 +39,17 @@ void MACAddress::findAllAddresses (Array<MACAddress>& result)
|
|||
{
|
||||
const sockaddr_dl* const sadd = (const sockaddr_dl*) cursor->ifa_addr;
|
||||
|
||||
#ifndef IFT_ETHER
|
||||
#define IFT_ETHER 6
|
||||
#endif
|
||||
#ifndef IFT_ETHER
|
||||
enum { IFT_ETHER = 6 };
|
||||
#endif
|
||||
|
||||
if (sadd->sdl_type == IFT_ETHER)
|
||||
result.addIfNotAlreadyThere (MACAddress (((const uint8*) sadd->sdl_data) + sadd->sdl_nlen));
|
||||
{
|
||||
MACAddress ma (MACAddress (((const uint8*) sadd->sdl_data) + sadd->sdl_nlen));
|
||||
|
||||
if (! ma.isNull())
|
||||
result.addIfNotAlreadyThere (ma);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -280,6 +280,12 @@ int64 File::getSize() const
|
|||
return juce_stat (fullPath, info) ? info.st_size : 0;
|
||||
}
|
||||
|
||||
uint64 File::getFileIdentifier() const
|
||||
{
|
||||
juce_statStruct info;
|
||||
return juce_stat (fullPath, info) ? (uint64) info.st_ino : 0;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
bool File::hasWriteAccess() const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -474,6 +474,28 @@ int64 File::getVolumeTotalSize() const
|
|||
return WindowsFileHelpers::getDiskSpaceInfo (getFullPathName(), true);
|
||||
}
|
||||
|
||||
uint64 File::getFileIdentifier() const
|
||||
{
|
||||
uint64 result = 0;
|
||||
|
||||
HANDLE h = CreateFile (getFullPathName().toWideCharPointer(),
|
||||
GENERIC_READ, FILE_SHARE_READ, nullptr,
|
||||
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
|
||||
|
||||
if (h != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
BY_HANDLE_FILE_INFORMATION info;
|
||||
zerostruct (info);
|
||||
|
||||
if (GetFileInformationByHandle (h, &info))
|
||||
result = (((uint64) info.nFileIndexHigh) << 32) | info.nFileIndexLow;
|
||||
|
||||
CloseHandle (h);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
bool File::isOnCDRomDrive() const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -287,7 +287,7 @@ private:
|
|||
|
||||
if (bytesToDo > 0
|
||||
&& ! InternetWriteFile (request,
|
||||
static_cast <const char*> (postData.getData()) + bytesSent,
|
||||
static_cast<const char*> (postData.getData()) + bytesSent,
|
||||
(DWORD) bytesToDo, &bytesDone))
|
||||
{
|
||||
break;
|
||||
|
|
@ -342,7 +342,13 @@ struct GetAdaptersInfoHelper
|
|||
|
||||
namespace MACAddressHelpers
|
||||
{
|
||||
void getViaGetAdaptersInfo (Array<MACAddress>& result)
|
||||
static void addAddress (Array<MACAddress>& result, const MACAddress& ma)
|
||||
{
|
||||
if (! ma.isNull())
|
||||
result.addIfNotAlreadyThere (ma);
|
||||
}
|
||||
|
||||
static void getViaGetAdaptersInfo (Array<MACAddress>& result)
|
||||
{
|
||||
GetAdaptersInfoHelper gah;
|
||||
|
||||
|
|
@ -350,11 +356,11 @@ namespace MACAddressHelpers
|
|||
{
|
||||
for (PIP_ADAPTER_INFO adapter = gah.adapterInfo; adapter != nullptr; adapter = adapter->Next)
|
||||
if (adapter->AddressLength >= 6)
|
||||
result.addIfNotAlreadyThere (MACAddress (adapter->Address));
|
||||
addAddress (result, MACAddress (adapter->Address));
|
||||
}
|
||||
}
|
||||
|
||||
void getViaNetBios (Array<MACAddress>& result)
|
||||
static void getViaNetBios (Array<MACAddress>& result)
|
||||
{
|
||||
DynamicLibrary dll ("netapi32.dll");
|
||||
JUCE_LOAD_WINAPI_FUNCTION (dll, Netbios, NetbiosCall, UCHAR, (PNCB))
|
||||
|
|
@ -396,7 +402,7 @@ namespace MACAddressHelpers
|
|||
ncb.ncb_length = sizeof (ASTAT);
|
||||
|
||||
if (NetbiosCall (&ncb) == 0 && astat.adapt.adapter_type == 0xfe)
|
||||
result.addIfNotAlreadyThere (MACAddress (astat.adapt.adapter_address));
|
||||
addAddress (result, MACAddress (astat.adapt.adapter_address));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue