Dayz
Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Toggle main menu visibility
Loading...
Searching...
No Matches
pluginfilehandler.c
Go to the documentation of this file.
1
class
PluginFileHandler
extends
PluginBase
2
{
3
static
bool
FileDuplicate
(
string
source_name,
string
dest_name)
4
{
5
return
CopyFile
(source_name, dest_name);
6
}
7
8
static
bool
FileDelete
(
string
file)
9
{
10
return
DeleteFile
(file);
11
}
12
13
static
void
FileRename
(
string
source_name,
string
dest_name)
14
{
15
FileDuplicate
(source_name, dest_name);
16
FileDelete
(source_name);
17
}
18
19
bool
m_ReadOnly
;
20
int
m_LineLimit
;
21
22
ref
TStringArray
m_FileContent
;
23
24
void
PluginFileHandler
()
25
{
26
m_FileContent
=
new
TStringArray
;
27
m_LineLimit
= -1;
28
29
LoadFile
();
30
}
31
32
void
~PluginFileHandler
()
33
{
34
ClearFileNoSave
();
35
}
36
37
override
void
OnInit
()
38
{
39
super.OnInit();
40
}
41
42
string
GetFileName
()
43
{
44
return
string
.
Empty
;
45
}
46
47
string
GetSubFolderName
()
48
{
49
return
string
.
Empty
;
50
}
51
52
void
ClearFileNoSave
()
53
{
54
m_FileContent
.Clear();
55
}
56
57
bool
LoadFile
()
58
{
59
ClearFileNoSave
();
60
61
FileHandle
file_index =
OpenFile
(
GetFileName
(),
FileMode
.READ);
62
63
if
( file_index == 0 )
64
{
65
return
false
;
66
}
67
68
string
line_content =
""
;
69
int
char_count =
FGets
( file_index, line_content );
70
while
( char_count != -1 )
71
{
72
m_FileContent
.Insert(line_content);
73
74
char_count =
FGets
( file_index, line_content );
75
}
76
77
CloseFile
(file_index);
78
79
return
true
;
80
}
81
82
bool
SaveFile
()
83
{
84
if
(
m_ReadOnly
)
85
{
86
return
false
;
87
}
88
89
if
(
GetSubFolderName
() && !
FileExist
(
GetSubFolderName
()))
90
{
91
MakeDirectory
(
GetSubFolderName
());
92
}
93
94
//Log("SaveFile -> Opening File: "+GetFileName());
95
96
FileHandle
file_index =
OpenFile
(
GetFileName
(),
FileMode
.WRITE);
97
98
if
( file_index == 0 )
99
{
100
return
false
;
101
}
102
103
for
(
int
i = 0; i <
m_FileContent
.Count(); ++i)
104
{
105
//Log("SaveFile -> Writing: "+m_FileContent.Get(i));
106
FPrintln
(file_index,
m_FileContent
.Get(i));
107
}
108
109
CloseFile
(file_index);
110
111
return
true
;
112
}
113
114
bool
IsReadOnly
()
115
{
116
return
m_ReadOnly
;
117
}
118
119
void
AddText
(
string
text)
120
{
121
AddNewLineNoSave
(text);
122
SaveFile
();
123
}
124
125
void
AddNewLineNoSave
(
string
text)
126
{
127
if
(
m_LineLimit
> -1 )
128
{
129
if
(
m_LineLimit
== 0 )
130
{
131
return
;
132
}
133
134
int
lines_count =
m_FileContent
.Count();
135
136
if
( lines_count > 0 && lines_count >=
m_LineLimit
)
137
{
138
int
remove_indexes = lines_count -
m_LineLimit
;
139
140
for
(
int
i = 0; i <= remove_indexes; ++i )
141
{
142
m_FileContent
.RemoveOrdered(0);
143
}
144
}
145
}
146
147
m_FileContent
.Insert(text);
148
}
149
150
TStringArray
GetFileContent
()
151
{
152
return
m_FileContent
;
153
}
154
}
PluginBase
Class PluginMessageManager provides some basic Message Distribution mechanics, if you get instance of...
Definition
pluginbase.c:2
PluginBase::OnInit
override void OnInit()
Definition
pluginfilehandler.c:37
PluginBase::m_ReadOnly
bool m_ReadOnly
Definition
pluginfilehandler.c:19
PluginBase::AddNewLineNoSave
void AddNewLineNoSave(string text)
Definition
pluginfilehandler.c:125
PluginBase::IsReadOnly
bool IsReadOnly()
Definition
pluginfilehandler.c:114
PluginBase::PluginFileHandler
void PluginFileHandler()
Definition
pluginfilehandler.c:24
PluginBase::AddText
void AddText(string text)
Definition
pluginfilehandler.c:119
PluginBase::FileRename
static void FileRename(string source_name, string dest_name)
Definition
pluginfilehandler.c:13
PluginBase::LoadFile
bool LoadFile()
Definition
pluginfilehandler.c:57
PluginBase::ClearFileNoSave
void ClearFileNoSave()
Definition
pluginfilehandler.c:52
PluginBase::FileDuplicate
static bool FileDuplicate(string source_name, string dest_name)
Definition
pluginfilehandler.c:3
PluginBase::FileDelete
static bool FileDelete(string file)
Definition
pluginfilehandler.c:8
PluginBase::~PluginFileHandler
void ~PluginFileHandler()
Definition
pluginfilehandler.c:32
PluginBase::GetFileContent
TStringArray GetFileContent()
Definition
pluginfilehandler.c:150
PluginBase::m_LineLimit
int m_LineLimit
Definition
pluginfilehandler.c:20
PluginBase::GetSubFolderName
string GetSubFolderName()
Definition
pluginfilehandler.c:47
PluginBase::GetFileName
string GetFileName()
Definition
pluginfilehandler.c:42
PluginBase::m_FileContent
ref TStringArray m_FileContent
Definition
pluginfilehandler.c:22
PluginBase::SaveFile
bool SaveFile()
Definition
pluginfilehandler.c:82
PluginFileHandler
Definition
pluginconfighandler.c:2
PluginFileHandler::GetFileName
override string GetFileName()
Definition
pluginconfighandler.c:17
TStringArray
array< string > TStringArray
Definition
enscript.c:712
FileMode
FileMode
Definition
ensystem.c:383
CloseFile
proto void CloseFile(FileHandle file)
Close the File.
MakeDirectory
proto native bool MakeDirectory(string name)
Makes a directory.
CopyFile
proto native bool CopyFile(string sourceName, string destName)
copy file. destName must be "$profile:" or "$saves:" location
FGets
proto int FGets(FileHandle file, string var)
Get line from file, every next call of this function returns next line.
OpenFile
proto FileHandle OpenFile(string name, FileMode mode)
Opens File.
FileHandle
int[] FileHandle
Definition
ensystem.c:390
FileExist
proto bool FileExist(string name)
Check existence of file.
DeleteFile
proto native bool DeleteFile(string name)
delete file. Works only on "$profile:" and "$saves:" locations
FPrintln
proto void FPrintln(FileHandle file, void var)
Write to file and add new line.
string::Empty
static const string Empty
Definition
enstring.c:7
GetSubFolderName
class PluginLocalEnscriptHistory extends PluginLocalHistoryBase GetSubFolderName()
Definition
pluginlocalenscripthistory.c:20
Games
Dayz
scripts
4_world
plugins
pluginbase
pluginfilehandler.c
Generated by
1.17.0