Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
pluginfilehandler.c
Go to the documentation of this file.
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
25 {
26 m_FileContent = new TStringArray;
27 m_LineLimit = -1;
28
29 LoadFile();
30 }
31
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
90 {
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}
Plugin interface for controlling of agent pool system.
Definition pluginbase.c:2
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
array< string > TStringArray
Definition enscript.c:709
FileMode
Definition ensystem.c:383
proto void CloseFile(FileHandle file)
Close the File.
proto native bool MakeDirectory(string name)
Makes a directory.
proto native bool CopyFile(string sourceName, string destName)
copy file. destName must be "$profile:" or "$saves:" location
proto int FGets(FileHandle file, string var)
Get line from file, every next call of this function returns next line.
proto FileHandle OpenFile(string name, FileMode mode)
Opens File.
int[] FileHandle
Definition ensystem.c:390
proto bool FileExist(string name)
Check existence of file.
proto native bool DeleteFile(string name)
delete file. Works only on "$profile:" and "$saves:" locations
proto void FPrintln(FileHandle file, void var)
Write to file and add new line.
class PluginLocalEnscriptHistory extends PluginLocalHistoryBase GetSubFolderName()