Skip to content

Commit 6a7aa61

Browse files
author
peterbclements
committed
Portability changes.
1 parent ea05039 commit 6a7aa61

File tree

1 file changed

+123
-135
lines changed

1 file changed

+123
-135
lines changed

diskfile.h

+123-135
Original file line numberDiff line numberDiff line change
@@ -1,137 +1,125 @@
1-
// This file is part of par2cmdline (a PAR 2.0 compatible file verification and
2-
// repair tool). See http://parchive.sourceforge.net for details of PAR 2.0.
3-
//
4-
// Copyright (c) 2003 Peter Brian Clements
5-
//
6-
// par2cmdline is free software; you can redistribute it and/or modify
7-
// it under the terms of the GNU General Public License as published by
8-
// the Free Software Foundation; either version 2 of the License, or
9-
// (at your option) any later version.
10-
//
11-
// par2cmdline is distributed in the hope that it will be useful,
12-
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14-
// GNU General Public License for more details.
15-
//
16-
// You should have received a copy of the GNU General Public License
17-
// along with this program; if not, write to the Free Software
18-
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19-
20-
#ifndef __DISKFILE_H__
21-
#define __DISKFILE_H__
22-
23-
// A disk file can be any type of file that par2cmdline needs
24-
// to read or write data from or to.
25-
26-
class DiskFile
27-
{
28-
public:
29-
DiskFile(void);
30-
~DiskFile(void);
31-
32-
// Create a file and set its length
33-
bool Create(string filename, u64 filesize);
34-
35-
// Write some data to the file
36-
bool Write(u64 offset, const void *buffer, size_t length);
37-
38-
// Open the file
39-
bool Open(void);
40-
bool Open(string filename);
41-
bool Open(string filename, u64 filesize);
42-
43-
// Check to see if the file is open
44-
#ifdef WIN32
45-
bool IsOpen(void) const {return hFile != INVALID_HANDLE_VALUE;}
46-
#else
47-
#if defined(__CYGWIN__) || defined(linux)
48-
bool IsOpen(void) const {return file != 0;}
49-
#else
50-
bool IsOpen(void) const {return handle != -1;}
51-
#endif
52-
#endif
53-
54-
// Read some data from the file
55-
bool Read(u64 offset, void *buffer, size_t length);
56-
57-
// Close the file
58-
void Close(void);
59-
60-
// Get the size of the file
61-
u64 FileSize(void) const {return filesize;}
62-
63-
// Get the name of the file
64-
string FileName(void) const {return filename;}
65-
66-
// Does the file exist
67-
bool Exists(void) const {return exists;}
68-
69-
// Rename the file
70-
bool Rename(void); // Pick a filename automatically
71-
bool Rename(string filename);
72-
73-
// Delete the file
74-
bool Delete(void);
75-
76-
public:
77-
static string GetCanonicalPathname(string filename);
78-
79-
static void SplitFilename(string filename, string &path, string &name);
80-
static string TranslateFilename(string filename);
81-
82-
static bool FileExists(string filename);
83-
static u64 GetFileSize(string filename);
84-
85-
// Search the specified path for files which match the specified wildcard
86-
// and return their names in a list.
87-
static list<string>* FindFiles(string path, string wildcard);
88-
89-
protected:
90-
string filename;
91-
u64 filesize;
92-
93-
// OS file handle
94-
#ifdef WIN32
95-
HANDLE hFile;
96-
#else
97-
#ifdef __CYGWIN__
98-
FILE *file;
1+
// This file is part of par2cmdline (a PAR 2.0 compatible file verification and
2+
// repair tool). See http://parchive.sourceforge.net for details of PAR 2.0.
3+
//
4+
// Copyright (c) 2003 Peter Brian Clements
5+
//
6+
// par2cmdline is free software; you can redistribute it and/or modify
7+
// it under the terms of the GNU General Public License as published by
8+
// the Free Software Foundation; either version 2 of the License, or
9+
// (at your option) any later version.
10+
//
11+
// par2cmdline is distributed in the hope that it will be useful,
12+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
// GNU General Public License for more details.
15+
//
16+
// You should have received a copy of the GNU General Public License
17+
// along with this program; if not, write to the Free Software
18+
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19+
20+
#ifndef __DISKFILE_H__
21+
#define __DISKFILE_H__
22+
23+
// A disk file can be any type of file that par2cmdline needs
24+
// to read or write data from or to.
25+
26+
class DiskFile
27+
{
28+
public:
29+
DiskFile(void);
30+
~DiskFile(void);
31+
32+
// Create a file and set its length
33+
bool Create(string filename, u64 filesize);
34+
35+
// Write some data to the file
36+
bool Write(u64 offset, const void *buffer, size_t length);
37+
38+
// Open the file
39+
bool Open(void);
40+
bool Open(string filename);
41+
bool Open(string filename, u64 filesize);
42+
43+
// Check to see if the file is open
44+
#ifdef WIN32
45+
bool IsOpen(void) const {return hFile != INVALID_HANDLE_VALUE;}
46+
#else
47+
bool IsOpen(void) const {return file != 0;}
48+
#endif
49+
50+
// Read some data from the file
51+
bool Read(u64 offset, void *buffer, size_t length);
52+
53+
// Close the file
54+
void Close(void);
55+
56+
// Get the size of the file
57+
u64 FileSize(void) const {return filesize;}
58+
59+
// Get the name of the file
60+
string FileName(void) const {return filename;}
61+
62+
// Does the file exist
63+
bool Exists(void) const {return exists;}
64+
65+
// Rename the file
66+
bool Rename(void); // Pick a filename automatically
67+
bool Rename(string filename);
68+
69+
// Delete the file
70+
bool Delete(void);
71+
72+
public:
73+
static string GetCanonicalPathname(string filename);
74+
75+
static void SplitFilename(string filename, string &path, string &name);
76+
static string TranslateFilename(string filename);
77+
78+
static bool FileExists(string filename);
79+
static u64 GetFileSize(string filename);
80+
81+
// Search the specified path for files which match the specified wildcard
82+
// and return their names in a list.
83+
static list<string>* FindFiles(string path, string wildcard);
84+
85+
protected:
86+
string filename;
87+
u64 filesize;
88+
89+
// OS file handle
90+
#ifdef WIN32
91+
HANDLE hFile;
9992
#else
100-
#ifdef linux
10193
FILE *file;
102-
#else
103-
int handle;
104-
#endif
105-
#endif
106-
#endif
107-
108-
// Current offset within the file
109-
u64 offset;
110-
111-
// Does the file exist
112-
bool exists;
113-
114-
protected:
115-
#ifdef WIN32
116-
static string ErrorMessage(DWORD error);
117-
#endif
118-
};
119-
120-
// This class keeps track of which DiskFile objects exist
121-
// and which file on disk they are associated with.
122-
// It is used to avoid a file being processed twice.
123-
class DiskFileMap
124-
{
125-
public:
126-
DiskFileMap(void);
127-
~DiskFileMap(void);
128-
129-
bool Insert(DiskFile *diskfile);
130-
void Remove(DiskFile *diskfile);
131-
DiskFile* Find(string filename) const;
132-
133-
protected:
134-
map<string, DiskFile*> diskfilemap; // Map from filename to DiskFile
135-
};
136-
137-
#endif // __DISKFILE_H__
94+
#endif
95+
96+
// Current offset within the file
97+
u64 offset;
98+
99+
// Does the file exist
100+
bool exists;
101+
102+
protected:
103+
#ifdef WIN32
104+
static string ErrorMessage(DWORD error);
105+
#endif
106+
};
107+
108+
// This class keeps track of which DiskFile objects exist
109+
// and which file on disk they are associated with.
110+
// It is used to avoid a file being processed twice.
111+
class DiskFileMap
112+
{
113+
public:
114+
DiskFileMap(void);
115+
~DiskFileMap(void);
116+
117+
bool Insert(DiskFile *diskfile);
118+
void Remove(DiskFile *diskfile);
119+
DiskFile* Find(string filename) const;
120+
121+
protected:
122+
map<string, DiskFile*> diskfilemap; // Map from filename to DiskFile
123+
};
124+
125+
#endif // __DISKFILE_H__

0 commit comments

Comments
 (0)