| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2009, Google Inc. | 2 * Copyright 2009, Google Inc. |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 */ | 30 */ |
| 31 | 31 |
| 32 | 32 |
| 33 // This file contains implementation for raw-data which may be used | 33 // This file contains implementation for raw-data which may be used |
| 34 // by the progressive streaming archive system | 34 // by the progressive streaming archive system |
| 35 | 35 |
| 36 #include "import/cross/raw_data.h" | 36 #include "import/cross/raw_data.h" |
| 37 #include "base/file_util.h" | 37 #include "base/file_util.h" |
| 38 #include "utils/cross/file_path_utils.h" |
| 39 #include "base/file_path.h" |
| 40 #include "base/file_util.h" |
| 38 | 41 |
| 39 #ifdef OS_MACOSX | 42 #ifdef OS_MACOSX |
| 40 #include <CoreFoundation/CoreFoundation.h> | 43 #include <CoreFoundation/CoreFoundation.h> |
| 41 #endif | 44 #endif |
| 42 | 45 |
| 43 #ifdef OS_WIN | 46 #ifdef OS_WIN |
| 44 #include <rpc.h> | 47 #include <rpc.h> |
| 45 #endif | 48 #endif |
| 46 | 49 |
| 50 using file_util::OpenFile; |
| 51 using file_util::CloseFile; |
| 52 using file_util::GetFileSize; |
| 53 |
| 47 namespace o3d { | 54 namespace o3d { |
| 48 | 55 |
| 49 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 56 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 50 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 57 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 51 // RawData class | 58 // RawData class |
| 52 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 59 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 53 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 60 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 54 | 61 |
| 55 O3D_DEFN_CLASS(RawData, ParamObject); | 62 O3D_DEFN_CLASS(RawData, ParamObject); |
| 56 | 63 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 67 } | 74 } |
| 68 | 75 |
| 69 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 76 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 70 RawData::Ref RawData::Create(ServiceLocator* service_locator, | 77 RawData::Ref RawData::Create(ServiceLocator* service_locator, |
| 71 const String &uri, | 78 const String &uri, |
| 72 const void *data, | 79 const void *data, |
| 73 size_t length) { | 80 size_t length) { |
| 74 return RawData::Ref(new RawData(service_locator, uri, data, length)); | 81 return RawData::Ref(new RawData(service_locator, uri, data, length)); |
| 75 } | 82 } |
| 76 | 83 |
| 84 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 85 RawData::Ref RawData::CreateFromFile(ServiceLocator* service_locator, |
| 86 const String &uri, |
| 87 const String& filename) { |
| 88 RawData::Ref data(Create(service_locator, uri, NULL, 0)); |
| 89 if (!data->SetFromFile(filename)) { |
| 90 data.Reset(); |
| 91 } |
| 92 |
| 93 return data; |
| 94 } |
| 77 | 95 |
| 78 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 96 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 79 RawData::~RawData() { | 97 RawData::~RawData() { |
| 80 Discard(); | 98 Discard(); |
| 81 } | 99 } |
| 82 | 100 |
| 83 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 101 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 102 bool RawData::SetFromFile(const String& filename) { |
| 103 FilePath filepath = UTF8ToFilePath(filename); |
| 104 FILE *file = OpenFile(filepath, "rb"); |
| 105 bool result = false; |
| 106 if (!file) { |
| 107 DLOG(ERROR) << "file not found \"" << filename << "\""; |
| 108 } else { |
| 109 // Determine the file's length |
| 110 int64 file_size64; |
| 111 if (!GetFileSize(filepath, &file_size64)) { |
| 112 DLOG(ERROR) << "error getting file size \"" << filename << "\""; |
| 113 } else { |
| 114 if (file_size64 > 0xffffffffLL) { |
| 115 DLOG(ERROR) << "file is too large \"" << filename << "\""; |
| 116 } else { |
| 117 size_t file_length = static_cast<size_t>(file_size64); |
| 118 |
| 119 // Load the file data into memory |
| 120 data_.reset(new uint8[file_length]); |
| 121 length_ = file_length; |
| 122 if (fread(data_.get(), file_length, 1, file) != 1) { |
| 123 DLOG(ERROR) << "error reading file \"" << filename << "\""; |
| 124 } else { |
| 125 result = true; |
| 126 } |
| 127 } |
| 128 } |
| 129 CloseFile(file); |
| 130 } |
| 131 |
| 132 return result; |
| 133 } |
| 134 |
| 135 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 84 const uint8 *RawData::GetData() const { | 136 const uint8 *RawData::GetData() const { |
| 85 // Return data immediately if we have it | 137 // Return data immediately if we have it |
| 86 if (data_.get()) { | 138 if (data_.get()) { |
| 87 return data_.get(); | 139 return data_.get(); |
| 88 } | 140 } |
| 89 | 141 |
| 90 // We need to load the data from the cache file | 142 // We need to load the data from the cache file |
| 91 if (temp_filepath_.empty()) { | 143 if (temp_filepath_.empty()) { |
| 92 DLOG(ERROR) << "cannot retrieve data object - it has been released"; | 144 DLOG(ERROR) << "cannot retrieve data object - it has been released"; |
| 93 return NULL; | 145 return NULL; |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 // Construct the full pathname | 389 // Construct the full pathname |
| 338 FilePath fullpath = temp_path; | 390 FilePath fullpath = temp_path; |
| 339 fullpath = fullpath.AppendASCII(filename); | 391 fullpath = fullpath.AppendASCII(filename); |
| 340 | 392 |
| 341 if (temp_fullpath) *temp_fullpath = fullpath; | 393 if (temp_fullpath) *temp_fullpath = fullpath; |
| 342 | 394 |
| 343 return true; | 395 return true; |
| 344 } | 396 } |
| 345 | 397 |
| 346 } // namespace o3d | 398 } // namespace o3d |
| OLD | NEW |