src/demo.cpp

changeset 15
3d3e5f0fc4cc
parent 13
9bdddd2ccde6
child 17
b41d74bacdea
equal deleted inserted replaced
14:825d9ed1ee01 15:3d3e5f0fc4cc
36 36
37 for (const qchar& c : in) { 37 for (const qchar& c : in) {
38 if (skip-- > 0) 38 if (skip-- > 0)
39 continue; 39 continue;
40 40
41 if (c.toAscii() == '\034') { 41 #if (QT_VERSION >= QT_VERSION_CHECK (5, 0, 0))
42 if (c.toLatin1() == '\034')
43 #else
44 if (c.toAscii() == '\034')
45 #endif // QT_VERSION
46 {
42 skip = 1; 47 skip = 1;
43 continue; 48 continue;
44 } 49 }
45 50
46 out += c; 51 out += c;
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);

mercurial