Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: chrome/installer/test/resource_updater.cc

Issue 5236002: Add infrastructure enabling tests of installer upgrade scenarios.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/installer/test/resource_updater.h"
6
7 #include <windows.h>
8
9 #include "base/file_path.h"
10 #include "base/file_util.h"
11 #include "base/logging.h"
12
13 namespace upgrade_test {
14
15 ResourceUpdater::ResourceUpdater() : handle_(NULL) {
16 }
17
18 ResourceUpdater::~ResourceUpdater() {
19 if (handle_ != NULL) {
20 // An update wasn't committed, so discard it.
21 BOOL result = EndUpdateResource(handle_, TRUE);
22 DPCHECK(result != FALSE) << "EndUpdateResource failed";
23 }
24 }
25
26 bool ResourceUpdater::Initialize(const FilePath& pe_image_path) {
27 DCHECK(handle_ == NULL);
28 handle_ = BeginUpdateResource(pe_image_path.value().c_str(), FALSE);
29 if (handle_ == NULL) {
30 PLOG(DFATAL)
31 << "BeginUpdateResource failed on \"" << pe_image_path.value() << "\"";
32 return false;
33 }
34 return true;
35 }
36
37 bool ResourceUpdater::Update(const std::wstring& name,
38 const std::wstring& type,
39 WORD language_id, const FilePath& input_file) {
40 DCHECK(handle_ != NULL);
41 file_util::MemoryMappedFile input;
42
43 if (input.Initialize(input_file)) {
44 if (UpdateResource(handle_, type.c_str(), name.c_str(), language_id,
45 const_cast<uint8*>(input.data()), input.length())
46 != FALSE) {
47 return true;
48 }
49 PLOG(DFATAL) << "UpdateResource failed for resource \"" << name << "\"";
50 } else {
51 PLOG(DFATAL) << "Failed mapping \"" << input_file.value() << "\"";
52 }
53 return false;
54 }
55
56 bool ResourceUpdater::Commit() {
57 DCHECK(handle_ != NULL);
58 bool result = true;
59 if (EndUpdateResource(handle_, FALSE) == FALSE) {
60 PLOG(DFATAL) << "EndUpdateResource failed";
61 result = false;
62 }
63 handle_ = NULL;
64 return result;
65 }
66
67 } // namespace upgrade_test
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698