-
Notifications
You must be signed in to change notification settings - Fork 2
/
myfile.cpp
142 lines (126 loc) · 2.87 KB
/
myfile.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include "stdafx.h"
#include "myfile.h"
#include "mytxt.h"
/*
typedef struct file
{
HFILE h;
} file;
*/
txt* file_error;
txt* file_error_name;
file* open(LPCSTR name)
{
static file* tf;
static OFSTRUCT fs;
tf=(file*)malloc(sizeof(file));
tf->h=HFILE_ERROR;
tf->h=OpenFile(name,&fs,OF_READWRITE|OF_SHARE_COMPAT);
if (tf->h==HFILE_ERROR){
file_error_name=txtnew(); txtset(file_error_name,name);
file_error=txtnew(); txtset(file_error,"File "); txtadd(file_error,file_error_name); txtadd(file_error," not found");
MessageBox(NULL,file_error->d,"Ultima 6 Online",MB_OK);
}
return tf;
}
file* open2(LPCSTR name, unsigned long flags)
{
static file* tf;
static OFSTRUCT fs;
tf=(file*)malloc(sizeof(file));
tf->h=HFILE_ERROR;
tf->h=OpenFile(name,&fs,flags);
return tf;
}
file* open2(txt *t, unsigned long flags)
{
static file* tf;
static OFSTRUCT fs;
tf=(file*)malloc(sizeof(file));
tf->h=HFILE_ERROR;
tf->h=OpenFile(t->d,&fs,flags);
return tf;
}
/*
typedef struct txt
{
char* d; //pointer to data
long l; //length of text in buffer
long bl; //length of current buffer
} txt;
*/
file* open(txt*t)
{
static file* tf;
static OFSTRUCT fs;
tf=(file*)malloc(sizeof(file));
tf->h=HFILE_ERROR;
tf->h=OpenFile(t->d,&fs,OF_READWRITE|OF_SHARE_COMPAT);
if (tf->h==HFILE_ERROR){
txtset(file_error_name,t);
file_error=txtnew(); txtset(file_error,"File "); txtadd(file_error,file_error_name); txtadd(file_error," not found");
MessageBox(NULL,file_error->d,"Ultima 6 Online",MB_OK);
}
return tf;
}
void get(file* filepointer,void* destoffset,long bytes)
{
if (filepointer->h!=HFILE_ERROR) _hread(filepointer->h,destoffset,bytes);
return;
}
void put(file* filepointer,void* sourceoffset,long bytes)
{
if (filepointer->h!=HFILE_ERROR) _hwrite(filepointer->h,(LPCSTR)sourceoffset,bytes);
return;
}
void seek(file* filepointer,long fileoffset)
{
if (filepointer->h!=HFILE_ERROR) _llseek(filepointer->h,fileoffset,FILE_BEGIN);
return;
}
void close(file* filepointer)
{
if (filepointer->h!=HFILE_ERROR) _lclose(filepointer->h);
free((void*)filepointer);
return;
}
long seek(file* filepointer)
{
if (filepointer->h==HFILE_ERROR) return 0;
return _llseek(filepointer->h,0,FILE_CURRENT);
}
long lof(file* filepointer)
{
if (filepointer->h==HFILE_ERROR) return 0;
static long i,i2;
i=_llseek(filepointer->h,0,FILE_CURRENT);
i2=_llseek(filepointer->h,0,FILE_END);
_llseek(filepointer->h,i,FILE_BEGIN);
return i2;
}
long loadfile_FILESIZE;
void* loadfile(LPCSTR name)
{
static file* f;
static void* v;
f=open(name);
if (f->h!=HFILE_ERROR) return NULL;
loadfile_FILESIZE=lof(f);
v=malloc(loadfile_FILESIZE);
get(f,v,loadfile_FILESIZE);
close(f);
return v;
}
void waitforfile(LPCSTR name){
static OFSTRUCT fs;
static HFILE hfile;
waitforfile_retry:
hfile=OpenFile(name,&fs,OF_SHARE_EXCLUSIVE|OF_READWRITE);
if (hfile==HFILE_ERROR) goto waitforfile_retry;
_lclose(hfile);
}
void deletefile(LPCSTR name){
static OFSTRUCT fs;
OpenFile(name,&fs,OF_DELETE);
return;
}