| OLD | NEW |
| (Empty) |
| 1 // Copyright 2010 Google Inc. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 // ======================================================================== | |
| 15 | |
| 16 #include "omaha/goopdate/offline_utils.h" | |
| 17 #include <atlpath.h> | |
| 18 #include "omaha/base/debug.h" | |
| 19 #include "omaha/base/file.h" | |
| 20 #include "omaha/base/logging.h" | |
| 21 #include "omaha/base/path.h" | |
| 22 | |
| 23 namespace omaha { | |
| 24 | |
| 25 namespace offline_utils { | |
| 26 | |
| 27 CString GetV2OfflineManifest(const CString& app_id, | |
| 28 const CString& offline_dir) { | |
| 29 CPath manifest_filename(app_id); | |
| 30 VERIFY1(manifest_filename.AddExtension(_T(".gup"))); | |
| 31 return ConcatenatePath(offline_dir, manifest_filename); | |
| 32 } | |
| 33 | |
| 34 HRESULT FindV2OfflinePackagePath(const CString& offline_app_dir, | |
| 35 CString* package_path) { | |
| 36 ASSERT1(!offline_app_dir.IsEmpty()); | |
| 37 ASSERT1(package_path); | |
| 38 package_path->Empty(); | |
| 39 | |
| 40 CORE_LOG(L3, (_T("[FindV2OfflinePackagePath][%s]"), offline_app_dir)); | |
| 41 | |
| 42 CString pattern(_T("*")); | |
| 43 std::vector<CString> files; | |
| 44 HRESULT hr = FindFiles(offline_app_dir, pattern, &files); | |
| 45 if (FAILED(hr)) { | |
| 46 return hr; | |
| 47 } | |
| 48 | |
| 49 if (files.size() != 3) { | |
| 50 CORE_LOG(LE, (_T("[Cannot guess filename with multiple files]"))); | |
| 51 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); | |
| 52 } | |
| 53 | |
| 54 CString local_package_path; | |
| 55 // Skip over "." and "..". | |
| 56 size_t i = 0; | |
| 57 for (; i < files.size(); ++i) { | |
| 58 local_package_path = ConcatenatePath(offline_app_dir, files[i]); | |
| 59 if (!File::IsDirectory(local_package_path)) { | |
| 60 break; | |
| 61 } | |
| 62 } | |
| 63 if (i == files.size()) { | |
| 64 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); | |
| 65 } | |
| 66 | |
| 67 CORE_LOG(L3, (_T("[Non-standard/legacy package][%s]"), local_package_path)); | |
| 68 *package_path = local_package_path; | |
| 69 return S_OK; | |
| 70 } | |
| 71 | |
| 72 HRESULT ParseOfflineManifest(const CString& app_id, | |
| 73 const CString& offline_dir, | |
| 74 xml::UpdateResponse* update_response) { | |
| 75 CORE_LOG(L3, (_T("[ParseOfflineManifest][%s][%s]"), app_id, offline_dir)); | |
| 76 ASSERT1(update_response); | |
| 77 | |
| 78 CString manifest_path(ConcatenatePath(offline_dir, kOfflineManifestFileName)); | |
| 79 if (!File::Exists(manifest_path)) { | |
| 80 manifest_path = GetV2OfflineManifest(app_id, offline_dir); | |
| 81 } | |
| 82 | |
| 83 HRESULT hr = update_response->DeserializeFromFile(manifest_path); | |
| 84 if (FAILED(hr)) { | |
| 85 CORE_LOG(LE, (_T("[DeserializeFromFile failed][%s][0x%x]"), | |
| 86 manifest_path, hr)); | |
| 87 return hr; | |
| 88 } | |
| 89 | |
| 90 return S_OK; | |
| 91 } | |
| 92 | |
| 93 } // namespace offline_utils | |
| 94 | |
| 95 } // namespace omaha | |
| OLD | NEW |