Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
FileUtils.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_IO_FileSystem_FileUtils_h_
5#define _Stroika_Foundation_IO_FileSystem_FileUtils_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include <filesystem>
10#include <set>
11#include <vector>
12
13#if qStroika_Foundation_Common_Platform_Windows
14#include <Windows.h>
15#endif
16
17#include "Stroika/Foundation/Characters/SDKChar.h"
18#include "Stroika/Foundation/Common/Common.h"
21#include "Stroika/Foundation/IO/AccessMode.h"
22#include "Stroika/Foundation/IO/FileSystem/Common.h"
24
25/**
26 * TODO:
27 *
28 * o This file is obsolete, and will be gradually replaced - moving its contents out to other modules
29
30 */
31
33
34 String FileSizeToDisplayString (FileOffset_t bytes);
35
36 void SetFileAccessWideOpened (const filesystem::path& filePathName);
37
38#if qStroika_Foundation_Common_Platform_Windows
39 /**
40 * Sadly std::filesystem::is_symlink() doesn't work with some cygwin (old fashioned) symbolic links
41 */
42 bool is_cygwin_symlink (const filesystem::path& p);
43
44 /**
45 * Sadly std::filesystem::read_symlink() doesn't work with some cygwin (old fashioned) symbolic links
46 */
47 filesystem::path read_cygwin_symlink (const filesystem::path& p);
48#endif
49
50 /**
51 * Possibly useful, even after using std::filesystem, as I dont think supported in std::filesystem.
52 * but @todo DOCUMENT WHAT THIS DOES ***
53 */
54 String GetVolumeName (const filesystem::path& driveLetterAbsPath);
55
56 vector<String> FindFiles (const filesystem::path& path, const String& fileNameToMatch = L"*.*");
57
58 vector<String> FindFilesOneDirUnder (const filesystem::path& path, const String& fileNameToMatch = L"*.*");
59
60 void CopyFile (const filesystem::path& srcFile, const filesystem::path& destPath);
61
62// COULD be made portable but alot of changes needed
63#if qStroika_Foundation_Common_Platform_Windows
64 class DirectoryChangeWatcher {
65 private:
66 DirectoryChangeWatcher (const DirectoryChangeWatcher&) = delete;
67 void operator= (const DirectoryChangeWatcher&) = delete;
68
69 public:
70 DirectoryChangeWatcher (const filesystem::path& directoryName, bool watchSubTree = false, DWORD notifyFilter = FILE_NOTIFY_CHANGE_LAST_WRITE);
71 virtual ~DirectoryChangeWatcher ();
72
73 protected:
74 virtual void ValueChanged ();
75
76 private:
77 static void ThreadProc (void* lpParameter);
78
79 private:
80 String fDirectory;
81 bool fWatchSubTree;
82 Execution::Thread::Ptr fThread;
83 HANDLE fDoneEvent;
84 HANDLE fWatchEvent;
85 bool fQuitting;
86 };
87#endif
88
89// Should be in a PLATFORM_WINDOWS subfile or sub-namespace... And DOCUMENT!!!!
90#if qStroika_Foundation_Common_Platform_Windows
91 struct AdjustSysErrorMode {
92 static UINT GetErrorMode ();
93 AdjustSysErrorMode (UINT newErrorMode);
94 ~AdjustSysErrorMode ();
95 UINT fSavedErrorMode;
96 };
97#endif
98
99}
100
101/*
102 ********************************************************************************
103 ***************************** Implementation Details ***************************
104 ********************************************************************************
105 */
106#include "FileUtils.inl"
107
108#endif /*_Stroika_Foundation_IO_FileSystem_FileUtils_h_*/
String GetVolumeName(const filesystem::path &driveLetterAbsPath)