/[pcsx2_0.9.7]/trunk/pcsx2/CDVD/IsoFileTools.cpp
ViewVC logotype

Annotation of /trunk/pcsx2/CDVD/IsoFileTools.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (hide annotations) (download)
Tue Sep 7 03:24:11 2010 UTC (10 years, 7 months ago) by william
File size: 3173 byte(s)
committing r3113 initial commit again...
1 william 31 /* PCSX2 - PS2 Emulator for PCs
2     * Copyright (C) 2002-2010 PCSX2 Dev Team
3     *
4     * PCSX2 is free software: you can redistribute it and/or modify it under the terms
5     * of the GNU Lesser General Public License as published by the Free Software Found-
6     * ation, either version 3 of the License, or (at your option) any later version.
7     *
8     * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9     * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10     * PURPOSE. See the GNU General Public License for more details.
11     *
12     * You should have received a copy of the GNU General Public License along with PCSX2.
13     * If not, see <http://www.gnu.org/licenses/>.
14     */
15    
16     #include "PrecompiledHeader.h"
17     #include "IsoFileTools.h"
18    
19     #ifdef _WIN32
20     # include <wx/msw/wrapwin.h>
21    
22    
23     void *_openfile(const char *filename, int flags)
24     {
25     HANDLE handle;
26    
27     // Console.WriteLn("_openfile %s, %d", filename, flags & O_RDONLY);
28     if (flags & O_WRONLY)
29     {
30     int _flags = CREATE_NEW;
31     if (flags & O_CREAT) _flags = CREATE_ALWAYS;
32     handle = CreateFile(fromUTF8(filename), GENERIC_WRITE, 0, NULL, _flags, 0, NULL);
33     }
34     else
35     {
36     handle = CreateFile(fromUTF8(filename), GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
37     }
38    
39     return (handle == INVALID_HANDLE_VALUE) ? NULL : handle;
40     }
41    
42     u64 _tellfile(void *handle)
43     {
44     u64 ofs;
45     PLONG _ofs = (LONG*) & ofs;
46     _ofs[1] = 0;
47     _ofs[0] = SetFilePointer(handle, 0, &_ofs[1], FILE_CURRENT);
48     return ofs;
49     }
50    
51     int _seekfile(void *handle, u64 offset, int whence)
52     {
53     u64 ofs = (u64)offset;
54     PLONG _ofs = (LONG*) & ofs;
55    
56     // Console.WriteLn("_seekfile %p, %d_%d", handle, _ofs[1], _ofs[0]);
57    
58     SetFilePointer(handle, _ofs[0], &_ofs[1], (whence == SEEK_SET) ? FILE_BEGIN : FILE_END);
59    
60     return 0;
61     }
62    
63     u32 _readfile(void *handle, void *dst, int size)
64     {
65     DWORD ret;
66    
67     ReadFile(handle, dst, size, &ret, NULL);
68     // Console.WriteLn("_readfile(%p, %d) = %d; %d", handle, size, ret, GetLastError());
69     return ret;
70     }
71    
72     u32 _writefile(void *handle, const void *src, int size)
73     {
74     DWORD ret;
75    
76     // _seekfile(handle, _tellfile(handle));
77     WriteFile(handle, src, size, &ret, NULL);
78     // Console.WriteLn("_readfile(%p, %d) = %d", handle, size, ret);
79     return ret;
80     }
81    
82     void _closefile(void *handle)
83     {
84     CloseHandle(handle);
85     }
86    
87     #else
88    
89     void *_openfile(const char *filename, int flags)
90     {
91     // Console.WriteLn("_openfile %s %x", filename, flags);
92    
93     if (flags & O_WRONLY)
94     return fopen64(filename, "wb");
95     else
96     return fopen64(filename, "rb");
97     }
98    
99     u64 _tellfile(void *handle)
100     {
101     FILE* fp = (FILE*)handle;
102     s64 cursize = ftell(fp);
103    
104     if (cursize == -1)
105     {
106     // try 64bit
107     cursize = ftello64(fp);
108     if (cursize < -1)
109     {
110     // zero top 32 bits
111     cursize &= 0xffffffff;
112     }
113     }
114     return cursize;
115     }
116    
117     int _seekfile(void *handle, u64 offset, int whence)
118     {
119     int seekerr = fseeko64((FILE*)handle, offset, whence);
120    
121     if (seekerr == -1) Console.Error("Failed to seek.");
122    
123     return seekerr;
124     }
125    
126     u32 _readfile(void *handle, void *dst, int size)
127     {
128     return fread(dst, 1, size, (FILE*)handle);
129     }
130    
131     u32 _writefile(void *handle, const void *src, int size)
132     {
133     return fwrite(src, 1, size, (FILE*)handle);
134     }
135    
136     void _closefile(void *handle)
137     {
138     fclose((FILE*)handle);
139     }
140    
141     #endif

  ViewVC Help
Powered by ViewVC 1.1.22