Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
engine
Manage
Activity
Members
Labels
Plan
Redmine
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sip
engine
Commits
2efe4946
Commit
2efe4946
authored
Jul 5, 2019
by
Ivan Dokunov
Browse files
Options
Downloads
Patches
Plain Diff
CFileSystem refactor
parent
a6a21b96
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
source/core/FileSystem.cpp
+22
-20
22 additions, 20 deletions
source/core/FileSystem.cpp
source/core/FileSystem.h
+34
-31
34 additions, 31 deletions
source/core/FileSystem.h
with
56 additions
and
51 deletions
source/core/FileSystem.cpp
+
22
−
20
View file @
2efe4946
...
...
@@ -6,20 +6,6 @@
#include
<shellapi.h>
#include
<ShlObj.h>
void
CFileSystem
::
swithFileMode
(
IFile
*
file
,
const
char
*
szPath
,
FILE_OPEN_MODE
mode
)
{
switch
(
mode
)
{
case
FILE_MODE_WRITE
:
file
->
open
(
szPath
,
CORE_FILE_BIN
);
break
;
case
FILE_MODE_APPEND
:
file
->
add
(
szPath
,
CORE_FILE_BIN
);
break
;
}
}
//! Возвращает абсолютный канонизированный путь
char
*
CFileSystem
::
getAbsoliteCanonizePath
(
const
char
*
szPath
)
{
...
...
@@ -29,7 +15,14 @@ char *CFileSystem::getAbsoliteCanonizePath(const char *szPath)
int
len
=
absolute
?
strlen
(
szPath
)
+
1
:
MAX_PATH
;
char
*
fullPath
=
new
char
[
len
];
absolute
?
memcpy
(
fullPath
,
szPath
,
len
)
:
correctPath
=
resolvePath
(
szPath
,
fullPath
,
len
);
if
(
absolute
)
{
memcpy
(
fullPath
,
szPath
,
len
);
}
else
{
correctPath
=
resolvePath
(
szPath
,
fullPath
,
len
);
}
//Во время поиска пути могут произойти ошибки - путь может быть не найден, или слишком маленький буфер для записи
if
(
correctPath
)
...
...
@@ -62,9 +55,9 @@ String *CFileSystem::getFileName(const char *name)
{
LPWIN32_FIND_DATAA
wfd
;
HANDLE
const
hFind
=
FindFirstFile
(
name
,
wfd
);
HANDLE
hFind
=
FindFirstFile
(
name
,
wfd
);
F
indClose
(
hFind
);
F
IND_CLOSE
(
hFind
);
return
new
String
(
wfd
->
cFileName
[
0
]);
}
...
...
@@ -297,7 +290,7 @@ bool CFileSystem::deleteDirectory(const char *szPath)
""
};
// Если вернуло не 0, то все плохо
return
SHFileOperation
(
&
file_op
)
==
0
;
return
SHFileOperation
(
&
file_op
)
==
NO_ERROR
;
}
IFile
*
CFileSystem
::
openFile
(
const
char
*
szPath
,
FILE_OPEN_MODE
mode
=
FILE_MODE_READ
)
...
...
@@ -318,9 +311,9 @@ IFile *CFileSystem::openFile(const char *szPath, FILE_OPEN_MODE mode = FILE_MODE
IFile
*
file
=
new
CFile
;
//Если открываем только на чтение - то копирование не нужно (следовательно и выделение памяти тоже лишняя операция)
if
(
mode
==
FILE_MODE_READ
)
{
//Если открываем только на чтение - то копирование не нужно (следовательно и выделение памяти тоже лишняя операция)
file
->
open
(
fullPath
,
CORE_FILE_BIN
);
mem_delete_a
(
fullPath
);
return
file
;
...
...
@@ -328,7 +321,16 @@ IFile *CFileSystem::openFile(const char *szPath, FILE_OPEN_MODE mode = FILE_MODE
String
*
newFileName
=
copyFile
(
fullPath
);
swithFileMode
(
file
,
newFileName
->
c_str
(),
mode
);
switch
(
mode
)
{
case
FILE_MODE_WRITE
:
file
->
open
(
fullPath
,
CORE_FILE_BIN
);
break
;
case
FILE_MODE_APPEND
:
file
->
add
(
fullPath
,
CORE_FILE_BIN
);
break
;
}
mem_delete
(
newFileName
);
mem_delete_a
(
fullPath
);
...
...
This diff is collapsed.
Click to expand it.
source/core/FileSystem.h
+
34
−
31
View file @
2efe4946
...
...
@@ -10,6 +10,12 @@
handle = nullptr; \
}
#define FIND_CLOSE(handle) if (handle != INVALID_HANDLE_VALUE) \
{\
FindClose(handle); \
handle = nullptr; \
}
//! Сравнение длинны массива и буфера записи
#define CHECK_SIZE(len, buffSize) \
{ \
...
...
@@ -27,37 +33,6 @@
class
CFileSystem
final
:
public
IFileSystem
{
private:
//Метод нужен для вызора режима открытия файла в FileOpen
void
swithFileMode
(
IFile
*
file
,
const
char
*
szPath
,
FILE_OPEN_MODE
mode
);
//! Возвращает абсолютный канонизированный путь
char
*
getAbsoliteCanonizePath
(
const
char
*
szPath
);
char
*
getFullPathToBuild
();
String
*
getFileName
(
const
char
*
name
);
//! Вспомогательная функция для конвертирования FILETIME в time_t
time_t
convertFiletimeToTime_t
(
const
FILETIME
&
ft
);
HANDLE
getFileHandle
(
const
char
*
szPath
);
bool
isAbsolutePath
(
const
char
*
szPath
);
String
*
copyFile
(
const
char
*
szPath
);
//корневые пути и приоритет
Array
<
String
>
m_filePaths
;
Array
<
int
>
m_priority
;
//Полный путь к build
String
m_pathToBuild
;
//!Наш текущий ID корневого пути для записи
//! -1 - значит не установлен
int
m_writableRoot
=
-
1
;
public:
CFileSystem
();
...
...
@@ -99,6 +74,34 @@ public:
bool
deleteDirectory
(
const
char
*
szPath
)
override
;
IFile
*
openFile
(
const
char
*
szPath
,
FILE_OPEN_MODE
)
override
;
private:
//! Возвращает абсолютный канонизированный путь
char
*
getAbsoliteCanonizePath
(
const
char
*
szPath
);
char
*
getFullPathToBuild
();
String
*
getFileName
(
const
char
*
name
);
//! Вспомогательная функция для конвертирования FILETIME в time_t
time_t
convertFiletimeToTime_t
(
const
FILETIME
&
ft
);
HANDLE
getFileHandle
(
const
char
*
szPath
);
bool
isAbsolutePath
(
const
char
*
szPath
);
String
*
copyFile
(
const
char
*
szPath
);
//корневые пути и приоритет
Array
<
String
>
m_filePaths
;
Array
<
int
>
m_priority
;
//Полный путь к build
String
m_pathToBuild
;
//!Наш текущий ID корневого пути для записи
//! -1 - значит не установлен
int
m_writableRoot
=
-
1
;
};
#endif
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment