Browse Source

water: cleanup time handling, add back file time calls

Signed-off-by: falkTX <falktx@falktx.com>
pull/1780/head
falkTX 1 year ago
parent
commit
f279c54bdd
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
7 changed files with 107 additions and 156 deletions
  1. +4
    -6
      source/modules/water/files/DirectoryIterator.cpp
  2. +1
    -4
      source/modules/water/files/DirectoryIterator.h
  3. +64
    -28
      source/modules/water/files/File.cpp
  4. +20
    -16
      source/modules/water/files/File.h
  5. +0
    -28
      source/modules/water/misc/Time.cpp
  6. +18
    -73
      source/modules/water/misc/Time.h
  7. +0
    -1
      source/modules/water/water.h

+ 4
- 6
source/modules/water/files/DirectoryIterator.cpp View File

@@ -69,11 +69,10 @@ bool DirectoryIterator::fileMatches (const StringArray& wildCards, const String&
bool DirectoryIterator::next()
{
return next (nullptr, nullptr, nullptr, nullptr, nullptr);
return next (nullptr, nullptr, nullptr);
}
bool DirectoryIterator::next (bool* const isDirResult, int64* const fileSize,
Time* const modTime, Time* const creationTime, bool* const isReadOnly)
bool DirectoryIterator::next (bool* const isDirResult, int64* const fileSize, bool* const isReadOnly)
{
for (;;)
{
@@ -81,7 +80,7 @@ bool DirectoryIterator::next (bool* const isDirResult, int64* const fileSize,
if (subIterator != nullptr)
{
if (subIterator->next (isDirResult, fileSize, modTime, creationTime, isReadOnly))
if (subIterator->next (isDirResult, fileSize, isReadOnly))
return true;
subIterator = nullptr;
@@ -90,8 +89,7 @@ bool DirectoryIterator::next (bool* const isDirResult, int64* const fileSize,
String filename;
bool isDirectory, shouldContinue = false;
while (fileFinder.next (filename, &isDirectory,
fileSize, modTime, creationTime, isReadOnly))
while (fileFinder.next (filename, &isDirectory, fileSize, isReadOnly))
{
++index;


+ 1
- 4
source/modules/water/files/DirectoryIterator.h View File

@@ -101,8 +101,6 @@ public:
*/
bool next (bool* isDirectory,
int64* fileSize,
Time* modTime,
Time* creationTime,
bool* isReadOnly);
/** Returns the file that the iterator is currently pointing at.
@@ -127,8 +125,7 @@ private:
~NativeIterator();
bool next (String& filenameFound,
bool* isDirectory, int64* fileSize,
Time* modTime, Time* creationTime, bool* isReadOnly);
bool* isDirectory, int64* fileSize, bool* isReadOnly);
class Pimpl;


+ 64
- 28
source/modules/water/files/File.cpp View File

@@ -530,6 +530,28 @@ Result File::createDirectory() const
return r;
}
//==============================================================================
int64 File::getLastModificationTime() const
{
int64 m, _;
getFileTimesInternal (m, _, _);
return m;
}
int64 File::getLastAccessTime() const
{
int64 a, _;
getFileTimesInternal (_, a, _);
return a;
}
int64 File::getCreationTime() const
{
int64 c, _;
getFileTimesInternal (_, _, c);
return c;
}
//==============================================================================
bool File::loadFileAsData (MemoryBlock& destBlock) const
{
@@ -1054,6 +1076,23 @@ int64 File::getSize() const
return 0;
}
void File::getFileTimesInternal (int64& modificationTime, int64& accessTime, int64& creationTime) const
{
using namespace WindowsFileHelpers;
WIN32_FILE_ATTRIBUTE_DATA attributes;
if (GetFileAttributesExW (fullPath.toUTF16().c_str(), GetFileExInfoStandard, &attributes))
{
modificationTime = fileTimeToTime (&attributes.ftLastWriteTime);
creationTime = fileTimeToTime (&attributes.ftCreationTime);
accessTime = fileTimeToTime (&attributes.ftLastAccessTime);
}
else
{
creationTime = accessTime = modificationTime = 0;
}
}
bool File::deleteFile() const
{
if (! exists())
@@ -1186,9 +1225,7 @@ public:
FindClose (handle);
}
bool next (String& filenameFound,
bool* const isDir, int64* const fileSize,
Time* const modTime, Time* const creationTime, bool* const isReadOnly)
bool next (String& filenameFound, bool* const isDir, int64* const fileSize, bool* const isReadOnly)
{
using namespace WindowsFileHelpers;
WIN32_FIND_DATAW findData;
@@ -1214,8 +1251,6 @@ public:
if (isDir != nullptr) *isDir = ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
if (isReadOnly != nullptr) *isReadOnly = ((findData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0);
if (fileSize != nullptr) *fileSize = findData.nFileSizeLow + (((int64) findData.nFileSizeHigh) << 32);
if (modTime != nullptr) *modTime = Time (fileTimeToTime (&findData.ftLastWriteTime));
if (creationTime != nullptr) *creationTime = Time (fileTimeToTime (&findData.ftCreationTime));
return true;
}
@@ -1244,24 +1279,15 @@ namespace
&& WATER_STAT (fileName.toUTF8(), &info) == 0;
}
#if 0 //def CARLA_OS_MAC
static int64 getCreationTime (const water_statStruct& s) noexcept { return (int64) s.st_birthtime; }
#else
static int64 getCreationTime (const water_statStruct& s) noexcept { return (int64) s.st_ctime; }
#endif
void updateStatInfoForFile (const String& path, bool* const isDir, int64* const fileSize,
Time* const modTime, Time* const creationTime, bool* const isReadOnly)
void updateStatInfoForFile (const String& path, bool* const isDir, int64* const fileSize, bool* const isReadOnly)
{
if (isDir != nullptr || fileSize != nullptr || modTime != nullptr || creationTime != nullptr)
if (isDir != nullptr || fileSize != nullptr)
{
water_statStruct info;
const bool statOk = water_stat (path, info);
if (isDir != nullptr) *isDir = statOk && ((info.st_mode & S_IFDIR) != 0);
if (fileSize != nullptr) *fileSize = statOk ? (int64) info.st_size : 0;
if (modTime != nullptr) *modTime = Time (statOk ? (int64) info.st_mtime * 1000 : 0);
if (creationTime != nullptr) *creationTime = Time (statOk ? getCreationTime (info) * 1000 : 0);
}
if (isReadOnly != nullptr)
@@ -1307,6 +1333,22 @@ bool File::hasWriteAccess() const
return false;
}
void File::getFileTimesInternal (int64& modificationTime, int64& accessTime, int64& creationTime) const
{
water_statStruct info;
if (water_stat (fullPath, info))
{
modificationTime = (int64) info.st_mtime * 1000;
accessTime = (int64) info.st_atime * 1000;
creationTime = (int64) info.st_ctime * 1000;
}
else
{
modificationTime = accessTime = creationTime = 0;
}
}
int64 File::getSize() const
{
water_statStruct info;
@@ -1516,9 +1558,7 @@ public:
[enumerator release];
}
bool next (String& filenameFound,
bool* const isDir, int64* const fileSize,
Time* const modTime, Time* const creationTime, bool* const isReadOnly)
bool next (String& filenameFound, bool* const isDir, int64* const fileSize,bool* const isReadOnly)
{
const AutoNSAutoreleasePool arpool;
@@ -1540,7 +1580,7 @@ public:
continue;
const String fullPath (parentDir + filenameFound);
updateStatInfoForFile (fullPath, isDir, fileSize, modTime, creationTime, isReadOnly);
updateStatInfoForFile (fullPath, isDir, fileSize, isReadOnly);
return true;
}
@@ -1661,9 +1701,7 @@ public:
closedir (dir);
}
bool next (String& filenameFound,
bool* const isDir, int64* const fileSize,
Time* const modTime, Time* const creationTime, bool* const isReadOnly)
bool next (String& filenameFound, bool* const isDir, int64* const fileSize,bool* const isReadOnly)
{
if (dir != nullptr)
{
@@ -1683,7 +1721,7 @@ public:
{
filenameFound = CharPointer_UTF8 (de->d_name);
updateStatInfoForFile (parentDir + filenameFound, isDir, fileSize, modTime, creationTime, isReadOnly);
updateStatInfoForFile (parentDir + filenameFound, isDir, fileSize, isReadOnly);
return true;
}
@@ -1709,11 +1747,9 @@ DirectoryIterator::NativeIterator::NativeIterator (const File& directory, const
DirectoryIterator::NativeIterator::~NativeIterator() {}
bool DirectoryIterator::NativeIterator::next (String& filenameFound,
bool* isDir, int64* fileSize,
Time* modTime, Time* creationTime, bool* isReadOnly)
bool DirectoryIterator::NativeIterator::next (String& filenameFound, bool* isDir, int64* fileSize,bool* isReadOnly)
{
return pimpl->next (filenameFound, isDir, fileSize, modTime, creationTime, isReadOnly);
return pimpl->next (filenameFound, isDir, fileSize, isReadOnly);
}
}

+ 20
- 16
source/modules/water/files/File.h View File

@@ -323,29 +323,32 @@ public:
*/
bool hasWriteAccess() const;
/** Changes the write-permission of a file or directory.
/** Returns true if this file is a hidden or system file.
The criteria for deciding whether a file is hidden are platform-dependent.
*/
bool isHidden() const;
//==============================================================================
/** Returns the last modification time of this file.
@param shouldBeReadOnly whether to add or remove write-permission
@param applyRecursively if the file is a directory and this is true, it will
recurse through all the subfolders changing the permissions
of all files
@returns true if it manages to change the file's permissions.
@see hasWriteAccess
@returns the time, or an invalid time if the file doesn't exist.
@see getLastAccessTime, getCreationTime
*/
bool setReadOnly (bool shouldBeReadOnly,
bool applyRecursively = false) const;
int64 getLastModificationTime() const;
/** Changes the execute-permissions of a file.
/** Returns the last time this file was accessed.
@param shouldBeExecutable whether to add or remove execute-permission
@returns true if it manages to change the file's permissions.
@returns the time, or an invalid time if the file doesn't exist.
@see getLastModificationTime, getCreationTime
*/
bool setExecutePermission (bool shouldBeExecutable) const;
int64 getLastAccessTime() const;
/** Returns true if this file is a hidden or system file.
The criteria for deciding whether a file is hidden are platform-dependent.
/** Returns the time that this file was created.
@returns the time, or an invalid time if the file doesn't exist.
@see getLastModificationTime, getLastAccessTime
*/
bool isHidden() const;
int64 getCreationTime() const;
//==============================================================================
/** Creates an empty file if it doesn't already exist.
@@ -770,6 +773,7 @@ private:
bool copyInternal (const File&) const;
bool moveInternal (const File&) const;
bool replaceInternal (const File&) const;
void getFileTimesInternal (int64& m, int64& a, int64& c) const;
bool setFileReadOnlyInternal (bool) const;
bool setFileExecutableInternal (bool) const;
};


+ 0
- 28
source/modules/water/misc/Time.cpp View File

@@ -98,34 +98,6 @@ static uint32 water_millisecondsSinceStartup() noexcept
}
//==============================================================================
Time::Time() noexcept : millisSinceEpoch (0)
{
}
Time::Time (const Time& other) noexcept : millisSinceEpoch (other.millisSinceEpoch)
{
}
Time::Time (const int64 ms) noexcept : millisSinceEpoch (ms)
{
}
Time::~Time() noexcept
{
}
Time& Time::operator= (const Time& other) noexcept
{
millisSinceEpoch = other.millisSinceEpoch;
return *this;
}
//==============================================================================
Time Time::getCurrentTime() noexcept
{
return Time (currentTimeMillis());
}
int64 Time::currentTimeMillis() noexcept
{


+ 18
- 73
source/modules/water/misc/Time.h View File

@@ -29,88 +29,33 @@
#include "../water.h"
namespace water {
namespace Time {
//==============================================================================
/**
Holds an absolute date and time.
// Static methods for getting system timers directly..
Internally, the time is stored at millisecond precision.
/** Returns the current system time.
@see RelativeTime
*/
class Time
{
public:
//==============================================================================
/** Creates a Time object.
This default constructor creates a time of midnight Jan 1st 1970 UTC, (which is
represented internally as 0ms).
To create a time object representing the current time, use getCurrentTime().
@see getCurrentTime
*/
Time() noexcept;
/** Creates a time based on a number of milliseconds.
To create a time object set to the current time, use getCurrentTime().
@param millisecondsSinceEpoch the number of milliseconds since the unix
'epoch' (midnight Jan 1st 1970 UTC).
@see getCurrentTime, currentTimeMillis
*/
explicit Time (int64 millisecondsSinceEpoch) noexcept;
/** Creates a copy of another Time object. */
Time (const Time& other) noexcept;
/** Destructor. */
~Time() noexcept;
/** Copies this time from another one. */
Time& operator= (const Time& other) noexcept;
Returns the number of milliseconds since midnight Jan 1st 1970 UTC.
//==============================================================================
/** Returns a Time object that is set to the current system time.
This may not be monotonic, as the system time can change at any moment.
You should therefore not use this method for measuring time intervals.
@see currentTimeMillis
*/
static Time getCurrentTime() noexcept;
//==============================================================================
// Static methods for getting system timers directly..
/** Returns the current system time.
Returns the number of milliseconds since midnight Jan 1st 1970 UTC.
Should be accurate to within a few millisecs, depending on platform,
hardware, etc.
*/
static int64 currentTimeMillis() noexcept;
/** Returns the number of millisecs since a fixed event (usually system startup).
Should be accurate to within a few millisecs, depending on platform,
hardware, etc.
*/
int64 currentTimeMillis() noexcept;
This returns a monotonically increasing value which it unaffected by changes to the
system clock. It should be accurate to within a few millisecs, depending on platform,
hardware, etc.
/** Returns the number of millisecs since a fixed event (usually system startup).
Being a 32-bit return value, it will of course wrap back to 0 after 2^32 seconds of
uptime, so be careful to take that into account. If you need a 64-bit time, you can
use currentTimeMillis() instead.
*/
static uint32 getMillisecondCounter() noexcept;
This returns a monotonically increasing value which it unaffected by changes to the
system clock. It should be accurate to within a few millisecs, depending on platform,
hardware, etc.
private:
//==============================================================================
int64 millisSinceEpoch;
};
Being a 32-bit return value, it will of course wrap back to 0 after 2^32 seconds of
uptime, so be careful to take that into account. If you need a 64-bit time, you can
use currentTimeMillis() instead.
*/
uint32 getMillisecondCounter() noexcept;
}
}
#endif // WATER_TIME_H_INCLUDED

+ 0
- 1
source/modules/water/water.h View File

@@ -78,7 +78,6 @@ class Result;
class String;
class StringArray;
class StringRef;
class Time;
class XmlElement;
class var;


Loading…
Cancel
Save