Changeset 1328 for cpp/common


Ignore:
Timestamp:
12/26/24 01:40:08 (37 hours ago)
Author:
Maciej Komosinski
Message:

Added Vstat(), Vdelete(), Vsettime() to VirtFILE

Location:
cpp/common/virtfile
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • cpp/common/virtfile/stdiofile.cpp

    r820 r1328  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2024  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    1111#include <common/dirs.h>
    1212#include <common/platform/android/AndroidAPK_DIR.h>
     13#endif
     14#include <sys/stat.h>
     15#include <unistd.h>
     16#ifdef _WIN32
     17#include <sys/utime.h>
     18#else
     19#include <utime.h>
    1320#endif
    1421
     
    7481}
    7582
     83bool StdioFileSystem::Vdelete(const char* path)
     84{
     85        return removeFile(path);
     86}
    7687
     88bool StdioFileSystem::Vstat(const char* path, Stat* out)
     89{
     90#ifdef _WIN32
     91        //under windows, there are a few choices of _statXX structures: 32bit, 64bit, ansi, widechar (and their corresponding _statXX() functions). For the future: ensure utf8 filenames work.
     92        using stat = struct _stat64i32; //"struct" because there is also a function with the same name
     93        //struct _stat64i32 info; //an alternative, simple way if one does not want to use "using" above
     94#else
     95        struct //if there was "using" earlier, then we cannot use "struct" in type name
     96#endif
     97        stat info;
     98        if (_stat(path, &info) != 0) return false;
     99        out->is_file = S_ISREG(info.st_mode);
     100#if defined IPHONE && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))
     101        out->modification_time = info.st_mtimespec.tv_sec;
     102#else
     103        out->modification_time = info.st_mtime;
     104#endif
     105        return true;
     106}
    77107
    78 
    79 
     108bool StdioFileSystem::Vsettime(const char* path, double timestamp)
     109{
     110#ifdef _WIN32
     111        //under windows, there are a few choices of _statXX structures: 32bit, 64bit, ansi, widechar (and their corresponding _statXX() functions). For the future: ensure utf8 filenames work.
     112        using stat = struct _stat64i32; //"struct" because there is also a function with the same name
     113        //struct _stat64i32 info; //an alternative, simple way if one does not want to use "using" above
     114#else
     115        struct //if there was "using" earlier, then we cannot use "struct" in type name
     116#endif
     117        stat info;
     118        if (_stat(path, &info) != 0) return false;
     119        struct utimbuf times;
     120#if defined IPHONE && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))
     121        times.actime = info.st_atimespec.tv_sec;
     122#else
     123        times.actime = info.st_atime;
     124#endif
     125        times.modtime = (time_t)timestamp;
     126        return utime(path, &times) == 0;
     127}
    80128
    81129#ifndef NO_STD_IN_OUT_ERR
  • cpp/common/virtfile/stdiofile.h

    r820 r1328  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2024  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    1818        bool Vmkdir(const char* path) { return makeDirectory(path); }
    1919        bool Vdirexists(const char* path, bool is_writable);
     20        bool Vdelete(const char* path);
     21        bool Vstat(const char* path, Stat* stat);
     22        bool Vsettime(const char* path, double timestamp);
    2023};
    2124
  • cpp/common/virtfile/virtfile.cpp

    r888 r1328  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2024  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    5050}
    5151
     52bool Vdelete(const char* path)
     53{
     54        return VirtFILE::vfs ? VirtFILE::vfs->Vdelete(path) : false;
     55}
     56
     57bool Vstat(const char* path, struct VirtFileSystem::Stat *stat)
     58{
     59        return VirtFILE::vfs ? VirtFILE::vfs->Vstat(path, stat) : false;
     60}
     61
     62bool Vsettime(const char* path, double timestamp)
     63{
     64        return VirtFILE::vfs ? VirtFILE::vfs->Vsettime(path, timestamp) : false;
     65}
    5266VirtFILE::~VirtFILE()
    5367{}
     
    99113bool VirtFileSystem::Vmkdir(const char* path) { return false; }
    100114bool VirtFileSystem::Vdirexists(const char* path, bool is_writable) { return false; }
     115bool VirtFileSystem::Vdelete(const char* path) { return false; }
     116bool VirtFileSystem::Vstat(const char* path, Stat* stat) { return false; }
     117bool VirtFileSystem::Vsettime(const char* path, double timestamp) { return false; }
    101118
    102119//////////////////////////////////////////////////////////////////////////
     
    206223{
    207224        return (chain != NULL) ? chain->Vdirexists(path, is_writable) : false;
     225}
     226
     227bool ChainFileSystem::Vdelete(const char* path)
     228{
     229        return (chain != NULL) ? chain->Vdelete(path) : false;
     230}
     231
     232bool ChainFileSystem::Vstat(const char* path, Stat* stat)
     233{
     234        return (chain != NULL) ? chain->Vstat(path, stat) : false;
     235}
     236
     237bool ChainFileSystem::Vsettime(const char* path, double timestamp)
     238{
     239        return (chain != NULL) ? chain->Vsettime(path, timestamp) : false;
    208240}
    209241
  • cpp/common/virtfile/virtfile.h

    r891 r1328  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2019  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2024  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    9898        virtual bool Vmkdirs(const char* path);
    9999        virtual bool Vdirexists(const char* path, bool is_writable);
     100        virtual bool Vdelete(const char* path);
     101        struct Stat { bool is_file; time_t modification_time; };
     102        virtual bool Vstat(const char* path, Stat* stat);
     103        virtual bool Vsettime(const char* path, double timestamp);
    100104};
    101105
     
    113117        bool Vmkdirs(const char* path);
    114118        bool Vdirexists(const char* path, bool is_writable);
     119        bool Vdelete(const char* path);
     120        bool Vstat(const char* path, Stat* stat);
     121        bool Vsettime(const char* path, double timestamp);
    115122
    116123        class Dir : public VirtDIR
     
    135142DLLEXP bool Vmkdirs(const char* path);
    136143DLLEXP bool Vdirexists(const char* path, bool is_writable);
     144DLLEXP bool Vdelete(const char* path);
     145DLLEXP bool Vstat(const char* path, struct VirtFileSystem::Stat *stat);
     146DLLEXP bool Vsettime(const char* path, double timestamp);
    137147
    138148#ifdef VIRTFILE_OVERLOADING
Note: See TracChangeset for help on using the changeset viewer.