| 375 | } |
| 376 | |
| 377 | bool CMarkup::LoadFromFile(LPCTSTR pstrFilename, int encoding) |
| 378 | { |
| 379 | Release(); |
| 380 | CDuiString sFile = CPaintManagerUI::GetResourcePath(); |
| 381 | if( CPaintManagerUI::GetResourceZip().IsEmpty() ) { |
| 382 | sFile += pstrFilename; |
| 383 | HANDLE hFile = ::CreateFile(sFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); |
| 384 | if( hFile == INVALID_HANDLE_VALUE ) return _Failed(_T("Error opening file")); |
| 385 | DWORD dwSize = ::GetFileSize(hFile, NULL); |
| 386 | if( dwSize == 0 ) return _Failed(_T("File is empty")); |
| 387 | if ( dwSize > 4096*1024 ) return _Failed(_T("File too large")); |
| 388 | |
| 389 | DWORD dwRead = 0; |
| 390 | BYTE* pByte = new BYTE[ dwSize ]; |
| 391 | ::ReadFile( hFile, pByte, dwSize, &dwRead, NULL ); |
| 392 | ::CloseHandle( hFile ); |
| 393 | |
| 394 | if( dwRead != dwSize ) { |
| 395 | delete[] pByte; |
| 396 | Release(); |
| 397 | return _Failed(_T("Could not read file")); |
| 398 | } |
| 399 | bool ret = LoadFromMem(pByte, dwSize, encoding); |
| 400 | delete[] pByte; |
| 401 | |
| 402 | return ret; |
| 403 | } |
| 404 | else { |
| 405 | sFile += CPaintManagerUI::GetResourceZip(); |
| 406 | HZIP hz = NULL; |
| 407 | if( CPaintManagerUI::IsCachedResourceZip() ) hz = (HZIP)CPaintManagerUI::GetResourceZipHandle(); |
| 408 | else hz = OpenZip((void*)sFile.GetData(), 0, 2); |
| 409 | if( hz == NULL ) return _Failed(_T("Error opening zip file")); |
| 410 | ZIPENTRY ze; |
| 411 | int i; |
| 412 | if( FindZipItem(hz, pstrFilename, true, &i, &ze) != 0 ) return _Failed(_T("Could not find ziped file")); |
| 413 | DWORD dwSize = ze.unc_size; |
| 414 | if( dwSize == 0 ) return _Failed(_T("File is empty")); |
| 415 | if ( dwSize > 4096*1024 ) return _Failed(_T("File too large")); |
| 416 | BYTE* pByte = new BYTE[ dwSize ]; |
| 417 | int res = UnzipItem(hz, i, pByte, dwSize, 3); |
| 418 | if( res != 0x00000000 && res != 0x00000600) { |
| 419 | delete[] pByte; |
| 420 | if( !CPaintManagerUI::IsCachedResourceZip() ) CloseZip(hz); |
| 421 | return _Failed(_T("Could not unzip file")); |
| 422 | } |
| 423 | if( !CPaintManagerUI::IsCachedResourceZip() ) CloseZip(hz); |
| 424 | bool ret = LoadFromMem(pByte, dwSize, encoding); |
| 425 | delete[] pByte; |
| 426 | |
| 427 | return ret; |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | void CMarkup::Release() |
| 432 | { |