Open Opens data file for reading or writing PARAM: type - UTM_OM_READING, UTM_OM_WRITING or UTM_OM_APPEND RETURN: -1 if error ************************************************/
| 185 | -1 if error |
| 186 | ************************************************/ |
| 187 | int CUT_FileDataSource::Open(OpenMsgType type) |
| 188 | { |
| 189 | if (_tcslen(m_szFileName) == 0) |
| 190 | return -1; |
| 191 | |
| 192 | // Open file for either reading or writing depending |
| 193 | // on the OpenMsgType |
| 194 | // |
| 195 | // nOpenMode specifies the open mode for the file. This can be either |
| 196 | // GENERIC_READ (to open file for reading) or GENERIC_WRITE (to open |
| 197 | // the file for writing. You may specify both of these using the bit- |
| 198 | // wise OR operator (|); this indicates the file is open for both |
| 199 | // reading and writing. |
| 200 | // |
| 201 | // dwCreationDisposition specifies what action to take when creating |
| 202 | // the file. See CUT_File::Open for more information |
| 203 | // |
| 204 | // bAppend specifies if the file should be open for appending. If a file |
| 205 | // is open for appending, *every* write operation occurs at the end of |
| 206 | // the file no matter where the file pointer is currently set. |
| 207 | |
| 208 | UINT nOpenMode; |
| 209 | DWORD dwCreationDisposition = OPEN_EXISTING; |
| 210 | BOOL bAppend = false; |
| 211 | |
| 212 | switch(type) { |
| 213 | |
| 214 | case UTM_OM_READING: |
| 215 | nOpenMode = GENERIC_READ; |
| 216 | break; |
| 217 | |
| 218 | case UTM_OM_WRITING: |
| 219 | nOpenMode = GENERIC_WRITE | GENERIC_READ; |
| 220 | dwCreationDisposition = CREATE_ALWAYS; |
| 221 | break; |
| 222 | |
| 223 | case UTM_OM_APPEND: |
| 224 | nOpenMode = GENERIC_WRITE | GENERIC_READ; |
| 225 | dwCreationDisposition = OPEN_ALWAYS; |
| 226 | bAppend = true; |
| 227 | break; |
| 228 | |
| 229 | default: |
| 230 | return -1; |
| 231 | } |
| 232 | |
| 233 | return m_file.Open(m_szFileName, nOpenMode, dwCreationDisposition, bAppend); |
| 234 | } |
| 235 | |
| 236 | /*********************************************** |
| 237 | Close |