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
35bd8336
Commit
35bd8336
authored
Jun 21, 2019
by
Ivan Dokunov
Browse files
Options
Downloads
Patches
Plain Diff
Bug fix
parent
c4d02cd6
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
source/core/FileSystem.cpp
+56
-41
56 additions, 41 deletions
source/core/FileSystem.cpp
source/core/FileSystem.h
+5
-8
5 additions, 8 deletions
source/core/FileSystem.h
source/xcommon/IFileSystem.h
+1
-2
1 addition, 2 deletions
source/xcommon/IFileSystem.h
with
62 additions
and
51 deletions
source/core/FileSystem.cpp
+
56
−
41
View file @
35bd8336
...
...
@@ -2,17 +2,19 @@
#include
"FileExtIterator.h"
#include
"FileExtsIterator.h"
#include
"DirIterator.h"
#include
"File.h"
#include
<shellapi.h>
#include
"File.h"
#include
<ShlObj.h>
String
CFileSystem
::
G
etFileName
(
const
char
*
name
)
String
*
CFileSystem
::
g
etFileName
(
const
char
*
name
)
{
LPWIN32_FIND_DATAA
wfd
;
HANDLE
const
hFind
=
FindFirstFile
(
name
,
wfd
);
return
String
(
wfd
->
cFileName
[
0
]);
FindClose
(
hFind
);
return
new
String
(
wfd
->
cFileName
[
0
]);
}
time_t
CFileSystem
::
convertFiletimeToTime_t
(
const
FILETIME
&
ft
)
...
...
@@ -48,46 +50,25 @@ bool CFileSystem::isAbsolutePath(const char *szPath)
return
false
;
}
IFile
*
CFileSystem
::
op
en
File
(
const
char
*
szPath
,
FILE_OPEN_MODE
mode
,
int
iType
)
String
*
CFileSystem
::
c
op
y
File
(
const
char
*
szPath
)
{
CFile
*
file
;
String
*
newFilePath
=
new
String
(
m_filePaths
[
m_writableRoot
]
+
'/'
+
getFileName
(
szPath
));
CopyFile
(
szPath
,
newFilePath
->
c_str
(),
false
);
if
(
fileExists
(
szPath
))
{
return
nullptr
;
}
String
fileName
;
switch
(
mode
)
{
case
FILE_MODE_READ
:
file
->
open
(
szPath
,
iType
);
break
;
case
FILE_MODE_WRITE
:
fileName
=
GetFileName
(
szPath
).
c_str
();
CopyFile
(
szPath
,
fileName
.
c_str
(),
false
);
file
->
open
(
fileName
.
c_str
(),
iType
);
break
;
case
FILE_MODE_APPEND
:
fileName
=
GetFileName
(
szPath
).
c_str
();
CopyFile
(
szPath
,
fileName
.
c_str
(),
false
);
file
->
add
(
fileName
.
c_str
(),
iType
);
break
;
default:
break
;
}
return
file
;
return
newFilePath
;
}
UINT
CFileSystem
::
addRoot
(
const
char
*
szPath
,
int
iPriority
)
{
m_filePaths
.
push_back
(
String
(
szPath
));
m_priority
.
push_back
(
iPriority
);
//Если у нас некорректный путь для записи и путь не является архивным
if
(
m_writableRoot
==
-
1
&&
szPath
[
0
]
!=
'@'
)
{
m_writableRoot
=
m_filePaths
.
size
()
-
1
;
}
return
m_filePaths
.
size
()
-
1
;
}
...
...
@@ -253,12 +234,46 @@ bool CFileSystem::deleteDirectory(const char *szPath)
return
SHFileOperation
(
&
file_op
)
==
0
;
}
IFile
*
CFileSystem
::
openFile
Text
(
const
char
*
szPath
,
FILE_OPEN_MODE
mode
=
FILE_MODE_READ
)
IFile
*
CFileSystem
::
openFile
(
const
char
*
szPath
,
FILE_OPEN_MODE
mode
=
FILE_MODE_READ
)
{
return
openFile
(
szPath
,
mode
,
CORE_FILE_TEXT
);
CFile
*
file
=
new
CFile
;
//Если путь не корректен
if
(
fileExists
(
szPath
))
{
return
nullptr
;
}
IFile
*
CFileSystem
::
openFileBin
(
const
char
*
szPath
,
FILE_OPEN_MODE
mode
=
FILE_MODE_READ
)
//Если путей на запись нет, и количество корневых путей нулевое
if
(
m_filePaths
.
size
()
==
0
)
{
return
openFile
(
szPath
,
mode
,
CORE_FILE_BIN
);
return
nullptr
;
}
String
*
newFileName
;
switch
(
mode
)
{
case
FILE_MODE_READ
:
file
->
open
(
szPath
,
CORE_FILE_BIN
);
break
;
case
FILE_MODE_WRITE
:
newFileName
=
copyFile
(
szPath
);
file
->
open
(
newFileName
->
c_str
(),
CORE_FILE_BIN
);
mem_delete
(
newFileName
);
break
;
case
FILE_MODE_APPEND
:
newFileName
=
copyFile
(
szPath
);
file
->
add
(
newFileName
->
c_str
(),
CORE_FILE_BIN
);
mem_delete
(
newFileName
);
break
;
default:
assert
(
false
&&
"You cannot use multiple opening types at the same time"
);
break
;
}
return
file
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
source/core/FileSystem.h
+
5
−
8
View file @
35bd8336
...
...
@@ -28,7 +28,7 @@
class
CFileSystem
final
:
public
IFileSystem
{
private:
String
CFileSystem
::
G
etFileName
(
const
char
*
name
);
String
*
g
etFileName
(
const
char
*
name
);
//! Вспомогательная функция для конвертирования FILETIME в time_t
time_t
convertFiletimeToTime_t
(
const
FILETIME
&
ft
);
...
...
@@ -37,14 +37,15 @@ private:
bool
isAbsolutePath
(
const
char
*
szPath
);
IFile
*
op
en
File
(
const
char
*
szPath
,
FILE_OPEN_MODE
mode
,
int
iType
);
String
*
c
op
y
File
(
const
char
*
szPath
);
//корневые пути и приоритет
Array
<
String
>
m_filePaths
;
Array
<
int
>
m_priority
;
//!Наш текущий ID корневого пути для записи
UINT
m_writableRoot
=
0
;
//! -1 - значит не установлен
int
m_writableRoot
=
-
1
;
public:
UINT
addRoot
(
const
char
*
szPath
,
int
iPriority
=
-
1
)
override
;
...
...
@@ -84,11 +85,7 @@ public:
bool
deleteDirectory
(
const
char
*
szPath
)
override
;
//! No implementation
IFile
*
openFileText
(
const
char
*
szPath
,
FILE_OPEN_MODE
)
override
;
//! No implementation
IFile
*
openFileBin
(
const
char
*
szPath
,
FILE_OPEN_MODE
)
override
;
IFile
*
openFile
(
const
char
*
szPath
,
FILE_OPEN_MODE
)
override
;
};
#endif
This diff is collapsed.
Click to expand it.
source/xcommon/IFileSystem.h
+
1
−
2
View file @
35bd8336
...
...
@@ -101,8 +101,7 @@ public:
virtual
bool
deleteDirectory
(
const
char
*
szPath
)
=
0
;
//! Открыть файл. При открытии с возможностью записи файла, находящегося вне записываемого корня, файл копируется в записывающийся корень и открывается копия.
virtual
IFile
*
openFileText
(
const
char
*
szPath
,
FILE_OPEN_MODE
mode
=
FILE_MODE_READ
)
=
0
;
virtual
IFile
*
openFileBin
(
const
char
*
szPath
,
FILE_OPEN_MODE
mode
=
FILE_MODE_READ
)
=
0
;
virtual
IFile
*
openFile
(
const
char
*
szPath
,
FILE_OPEN_MODE
mode
=
FILE_MODE_READ
)
=
0
;
};
#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