Skip to content

Commit 075f525

Browse files
committed
[ADD] : add a file test entry in the file system interface
1 parent 99b1c0d commit 075f525

2 files changed

Lines changed: 27 additions & 17 deletions

File tree

ImGuiFileDialog.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,9 @@ class FileSystemStd : public IGFD::IFileSystem {
437437
}
438438
return false; // this is not a directory!
439439
}
440+
bool IsFileExist(const std::string& vName) override {
441+
return fs::is_regular_file(vName);
442+
}
440443
bool CreateDirectoryIfNotExist(const std::string& vName) override {
441444
bool res = false;
442445
if (!vName.empty()) {
@@ -583,6 +586,14 @@ class FileSystemDirent : public IGFD::IFileSystem {
583586
}
584587
return bExists;
585588
}
589+
bool IsFileExist(const std::string& vName) override {
590+
std::ifstream docFile(vName, std::ios::in);
591+
if (docFile.is_open()) {
592+
docFile.close();
593+
return true;
594+
}
595+
return false;
596+
}
586597
bool CreateDirectoryIfNotExist(const std::string& vName) override {
587598
bool res = false;
588599
if (!vName.empty()) {
@@ -2295,15 +2306,6 @@ void IGFD::FileManager::SetCurrentPath(const std::string& vCurrentPath) {
22952306
m_CurrentPath = vCurrentPath;
22962307
}
22972308

2298-
bool IGFD::FileManager::IsFileExist(const std::string& vFile) {
2299-
std::ifstream docFile(vFile, std::ios::in);
2300-
if (docFile.is_open()) {
2301-
docFile.close();
2302-
return true;
2303-
}
2304-
return false;
2305-
}
2306-
23072309
void IGFD::FileManager::SetDefaultFileName(const std::string& vFileName) {
23082310
dLGDefaultFileName = vFileName;
23092311
IGFD::Utils::SetBuffer(fileNameBuffer, MAX_FILE_DIALOG_NAME_BUFFER, vFileName);
@@ -4694,7 +4696,7 @@ bool IGFD::FileDialog::m_Confirm_Or_OpenOverWriteFileDialog_IfNeeded(bool vLastA
46944696
(m_FileDialogInternal.dLGflags & ImGuiFileDialogFlags_ConfirmOverwrite)) {
46954697
if (m_FileDialogInternal.isOk) // catched only one time
46964698
{
4697-
if (!m_FileDialogInternal.fileManager.IsFileExist(GetFilePathName())) // not existing => quit dialog
4699+
if (!m_FileDialogInternal.fileManager.GetFileSystemInstance()->IsFileExist(GetFilePathName())) // not existing => quit dialog
46984700
{
46994701
m_QuitFrame();
47004702
return true;

ImGuiFileDialog.h

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,13 +1607,22 @@ class IGFD_API FileInfos {
16071607

16081608
class IFileSystem {
16091609
public:
1610-
virtual bool IsDirectoryCanBeOpened(const std::string& vName) = 0;
1611-
virtual bool IsDirectoryExist(const std::string& vName) = 0;
1612-
virtual bool CreateDirectoryIfNotExist(const std::string& vName) = 0;
1610+
// say if a directory can be openened or for any reason locked
1611+
virtual bool IsDirectoryCanBeOpened(const std::string& vName) = 0;
1612+
// say if a directory exist
1613+
virtual bool IsDirectoryExist(const std::string& vName) = 0;
1614+
// say if a file exist
1615+
virtual bool IsFileExist(const std::string& vName) = 0;
1616+
// say if a directory was created, return false if vName is invalid or alreayd exist
1617+
virtual bool CreateDirectoryIfNotExist(const std::string& vName) = 0;
1618+
// extract the component of a file apth name, like path, name, ext
16131619
virtual IGFD::Utils::PathStruct ParsePathFileName(const std::string& vPathFileName) = 0;
1614-
virtual std::vector<IGFD::FileInfos> ScanDirectory(const std::string& vPath) = 0;
1615-
virtual bool IsDirectory(const std::string& vFilePathName) = 0;
1616-
virtual std::vector<std::string> GetDrivesList() = 0;
1620+
// will return a list of files inside a path
1621+
virtual std::vector<IGFD::FileInfos> ScanDirectory(const std::string& vPath) = 0;
1622+
// say if the path is well a directory
1623+
virtual bool IsDirectory(const std::string& vFilePathName) = 0;
1624+
// return a drive list on windows, bu can be used on android or linux for give to the suer a list of root dir
1625+
virtual std::vector<std::string> GetDrivesList() = 0;
16171626
};
16181627

16191628
#pragma endregion
@@ -1739,7 +1748,6 @@ class IGFD_API FileManager {
17391748
bool SetPathOnParentDirectoryIfAny(); // compose paht on parent directory
17401749
std::string GetCurrentPath(); // get the current path
17411750
void SetCurrentPath(const std::string& vCurrentPath); // set the current path
1742-
static bool IsFileExist(const std::string& vFile);
17431751
void SetDefaultFileName(const std::string& vFileName);
17441752
bool SelectDirectory(const std::shared_ptr<FileInfos>& vInfos); // enter directory
17451753
void SelectFileName(const FileDialogInternal& vFileDialogInternal,

0 commit comments

Comments
 (0)