99 return ""; |
104 return ""; |
100 } |
105 } |
101 |
106 |
102 // ============================================================================= |
107 // ============================================================================= |
103 // ----------------------------------------------------------------------------- |
108 // ----------------------------------------------------------------------------- |
|
109 #ifdef _WIN32 |
|
110 # define FILE_FLAGS "rb" |
|
111 #else |
|
112 # define FILE_FLAGS "r" |
|
113 #endif // _WIN32 |
|
114 |
104 int launchDemo (str path) { |
115 int launchDemo (str path) { |
105 FILE* fp = fopen (path.toStdString().c_str(), "r"); |
116 FILE* fp = fopen (path.toStdString().c_str(), FILE_FLAGS); |
106 |
117 |
107 if (!fp) { |
118 if (!fp) { |
108 error (fmt (tr ("Couldn't open '%1' for reading: %2"), path, strerror (errno))); |
119 error (fmt (tr ("Couldn't open '%1' for reading: %2"), path, strerror (errno))); |
109 return 1; |
120 return 1; |
110 } |
121 } |
113 const size_t fsize = ftell (fp); |
124 const size_t fsize = ftell (fp); |
114 rewind (fp); |
125 rewind (fp); |
115 |
126 |
116 char* buf = new char[fsize]; |
127 char* buf = new char[fsize]; |
117 |
128 |
118 if (fread (buf, 1, fsize, fp) != fsize) { |
129 const size_t bytesRead = fread (buf, 1, fsize, fp); |
119 error (tr ("I/O error")); |
130 if (bytesRead != fsize) { |
|
131 error (fmt (tr ("I/O error: %1 / %2 bytes read"), bytesRead, fsize)); |
120 delete[] buf; |
132 delete[] buf; |
121 return 2; |
133 return 2; |
122 } |
134 } |
123 |
135 |
124 Bytestream s (buf, fsize); |
136 Bytestream s (buf, fsize); |