Commit 6f57e3ef authored by fdoray's avatar fdoray Committed by Commit bot

Return version of the generated file in GenerateAlternatePEFileVersion.

BUG=451546

Review-Url: https://codereview.chromium.org/2273103002
Cr-Commit-Position: refs/heads/master@{#414437}
parent 2e91f9ed
...@@ -56,22 +56,23 @@ ...@@ -56,22 +56,23 @@
namespace { namespace {
const wchar_t k7zaExe[] = L"7za.exe"; const base::char16 k7zaExe[] = L"7za.exe";
const wchar_t k7zaPathRelative[] = L"..\\..\\third_party\\lzma_sdk\\Executable"; const base::char16 k7zaPathRelative[] =
const wchar_t kB7[] = L"B7"; L"..\\..\\third_party\\lzma_sdk\\Executable";
const wchar_t kBl[] = L"BL"; const base::char16 kB7[] = L"B7";
const wchar_t kChromeBin[] = L"Chrome-bin"; const base::char16 kBl[] = L"BL";
const wchar_t kChromePacked7z[] = L"CHROME.PACKED.7Z"; const base::char16 kChromeBin[] = L"Chrome-bin";
const wchar_t kChrome7z[] = L"CHROME.7Z"; const base::char16 kChromePacked7z[] = L"CHROME.PACKED.7Z";
const wchar_t kExe[] = L"exe"; const base::char16 kChrome7z[] = L"CHROME.7Z";
const wchar_t kExpandExe[] = L"expand.exe"; const base::char16 kExe[] = L"exe";
const wchar_t kExtDll[] = L".dll"; const base::char16 kExpandExe[] = L"expand.exe";
const wchar_t kExtExe[] = L".exe"; const base::char16 kExtDll[] = L".dll";
const wchar_t kMakeCab[] = L"makecab.exe"; const base::char16 kExtExe[] = L".exe";
const wchar_t kSetupEx_[] = L"setup.ex_"; const base::char16 kMakeCab[] = L"makecab.exe";
const wchar_t kSetupExe[] = L"setup.exe"; const base::char16 kSetupEx_[] = L"setup.ex_";
const base::char16 kSetupExe[] = L"setup.exe";
const char kSwitch7zaPath[] = "7za_path"; const char kSwitch7zaPath[] = "7za_path";
const wchar_t kTempDirPrefix[] = L"mini_installer_test_temp"; const base::char16 kTempDirPrefix[] = L"mini_installer_test_temp";
// A helper class for creating and cleaning a temporary directory. A temporary // A helper class for creating and cleaning a temporary directory. A temporary
// directory is created in Initialize and destroyed (along with all of its // directory is created in Initialize and destroyed (along with all of its
...@@ -131,21 +132,21 @@ class ChromeVersion { ...@@ -131,21 +132,21 @@ class ChromeVersion {
DWORD low() const { return static_cast<DWORD>(version_); } DWORD low() const { return static_cast<DWORD>(version_); }
ULONGLONG value() const { return version_; } ULONGLONG value() const { return version_; }
void set_value(ULONGLONG value) { version_ = value; } void set_value(ULONGLONG value) { version_ = value; }
std::wstring ToString() const; base::string16 ToString() const;
std::string ToASCII() const; std::string ToASCII() const;
private: private:
ULONGLONG version_; ULONGLONG version_;
}; // class ChromeVersion }; // class ChromeVersion
std::wstring ChromeVersion::ToString() const { base::string16 ChromeVersion::ToString() const {
wchar_t buffer[24]; base::char16 buffer[24];
int string_len = int string_len =
swprintf_s(&buffer[0], arraysize(buffer), L"%hu.%hu.%hu.%hu", swprintf_s(&buffer[0], arraysize(buffer), L"%hu.%hu.%hu.%hu",
major(), minor(), build(), patch()); major(), minor(), build(), patch());
DCHECK_NE(-1, string_len); DCHECK_NE(-1, string_len);
DCHECK_GT(static_cast<int>(arraysize(buffer)), string_len); DCHECK_GT(static_cast<int>(arraysize(buffer)), string_len);
return std::wstring(&buffer[0], string_len); return base::string16(&buffer[0], string_len);
} }
std::string ChromeVersion::ToASCII() const { std::string ChromeVersion::ToASCII() const {
...@@ -217,7 +218,8 @@ bool MappedFile::Initialize(base::File file) { ...@@ -217,7 +218,8 @@ bool MappedFile::Initialize(base::File file) {
// Calls CreateProcess with good default parameters and waits for the process // Calls CreateProcess with good default parameters and waits for the process
// to terminate returning the process exit code. // to terminate returning the process exit code.
bool RunProcessAndWait(const wchar_t* exe_path, const std::wstring& cmdline, bool RunProcessAndWait(const base::char16* exe_path,
const base::string16& cmdline,
int* exit_code) { int* exit_code) {
bool result = true; bool result = true;
base::LaunchOptions options; base::LaunchOptions options;
...@@ -314,9 +316,9 @@ bool ReplaceAll(uint8_t* dest_first, ...@@ -314,9 +316,9 @@ bool ReplaceAll(uint8_t* dest_first,
// A context structure in support of our EnumResource_Fn callback. // A context structure in support of our EnumResource_Fn callback.
struct VisitResourceContext { struct VisitResourceContext {
ChromeVersion current_version; ChromeVersion current_version;
std::wstring current_version_str; base::string16 current_version_str;
ChromeVersion new_version; ChromeVersion new_version;
std::wstring new_version_str; base::string16 new_version_str;
}; // struct VisitResourceContext }; // struct VisitResourceContext
// Replaces the old version with the new in a resource. A first pass is made to // Replaces the old version with the new in a resource. A first pass is made to
...@@ -457,8 +459,8 @@ bool IncrementNewVersion(upgrade_test::Direction direction, ...@@ -457,8 +459,8 @@ bool IncrementNewVersion(upgrade_test::Direction direction,
// on success. // on success.
bool ApplyAlternateVersion(const base::FilePath& work_dir, bool ApplyAlternateVersion(const base::FilePath& work_dir,
upgrade_test::Direction direction, upgrade_test::Direction direction,
std::wstring* original_version, base::string16* original_version,
std::wstring* new_version) { base::string16* new_version) {
VisitResourceContext ctx; VisitResourceContext ctx;
if (!GetSetupExeVersion(work_dir, &ctx.current_version)) if (!GetSetupExeVersion(work_dir, &ctx.current_version))
return false; return false;
...@@ -473,7 +475,7 @@ bool ApplyAlternateVersion(const base::FilePath& work_dir, ...@@ -473,7 +475,7 @@ bool ApplyAlternateVersion(const base::FilePath& work_dir,
base::FilePath file = all_files.Next(); base::FilePath file = all_files.Next();
if (file.empty()) if (file.empty())
break; break;
std::wstring extension = file.Extension(); base::string16 extension = file.Extension();
if ((extension == &kExtExe[0] || extension == &kExtDll[0]) && if ((extension == &kExtExe[0] || extension == &kExtDll[0]) &&
!UpdateVersionIfMatch(file, &ctx)) { !UpdateVersionIfMatch(file, &ctx)) {
return false; return false;
...@@ -534,7 +536,7 @@ bool CreateArchive(const base::FilePath& output_file, ...@@ -534,7 +536,7 @@ bool CreateArchive(const base::FilePath& output_file,
compression_level >= 1 && compression_level <= 9 && compression_level >= 1 && compression_level <= 9 &&
(compression_level & 0x01) != 0); (compression_level & 0x01) != 0);
std::wstring command_line(1, L'"'); base::string16 command_line(1, L'"');
command_line command_line
.append(Get7zaPath().Append(&k7zaExe[0]).value()) .append(Get7zaPath().Append(&k7zaExe[0]).value())
.append(L"\" a -bd -t7z \"") .append(L"\" a -bd -t7z \"")
...@@ -562,8 +564,8 @@ namespace upgrade_test { ...@@ -562,8 +564,8 @@ namespace upgrade_test {
bool GenerateAlternateVersion(const base::FilePath& original_installer_path, bool GenerateAlternateVersion(const base::FilePath& original_installer_path,
const base::FilePath& target_path, const base::FilePath& target_path,
Direction direction, Direction direction,
std::wstring* original_version, base::string16* original_version,
std::wstring* new_version) { base::string16* new_version) {
// Create a temporary directory in which we'll do our work. // Create a temporary directory in which we'll do our work.
ScopedTempDirectory work_dir; ScopedTempDirectory work_dir;
if (!work_dir.Initialize()) if (!work_dir.Initialize())
...@@ -581,7 +583,7 @@ bool GenerateAlternateVersion(const base::FilePath& original_installer_path, ...@@ -581,7 +583,7 @@ bool GenerateAlternateVersion(const base::FilePath& original_installer_path,
base::FilePath setup_ex_ = work_dir.directory().Append(&kSetupEx_[0]); base::FilePath setup_ex_ = work_dir.directory().Append(&kSetupEx_[0]);
base::FilePath chrome_packed_7z; // Empty for component builds. base::FilePath chrome_packed_7z; // Empty for component builds.
base::FilePath chrome_7z; base::FilePath chrome_7z;
const wchar_t* archive_resource_name = nullptr; const base::char16* archive_resource_name = nullptr;
base::FilePath* archive_file = nullptr; base::FilePath* archive_file = nullptr;
// Load the original file and extract setup.ex_ and chrome.packed.7z // Load the original file and extract setup.ex_ and chrome.packed.7z
{ {
...@@ -629,7 +631,7 @@ bool GenerateAlternateVersion(const base::FilePath& original_installer_path, ...@@ -629,7 +631,7 @@ bool GenerateAlternateVersion(const base::FilePath& original_installer_path,
// Expand setup.ex_ // Expand setup.ex_
base::FilePath setup_exe = setup_ex_.ReplaceExtension(&kExe[0]); base::FilePath setup_exe = setup_ex_.ReplaceExtension(&kExe[0]);
std::wstring command_line; base::string16 command_line;
command_line.append(1, L'"') command_line.append(1, L'"')
.append(&kExpandExe[0]) .append(&kExpandExe[0])
.append(L"\" \"") .append(L"\" \"")
...@@ -723,27 +725,28 @@ bool GenerateAlternateVersion(const base::FilePath& original_installer_path, ...@@ -723,27 +725,28 @@ bool GenerateAlternateVersion(const base::FilePath& original_installer_path,
return base::Move(mini_installer, target_path); return base::Move(mini_installer, target_path);
} }
bool GenerateAlternatePEFileVersion(const base::FilePath& original_file, base::string16 GenerateAlternatePEFileVersion(
const base::FilePath& target_file, const base::FilePath& original_file,
Direction direction) { const base::FilePath& target_file,
Direction direction) {
VisitResourceContext ctx; VisitResourceContext ctx;
if (!GetFileVersion(original_file, &ctx.current_version)) { if (!GetFileVersion(original_file, &ctx.current_version)) {
LOG(DFATAL) << "Failed reading version from \"" << original_file.value() LOG(DFATAL) << "Failed reading version from \"" << original_file.value()
<< "\""; << "\"";
return false; return base::string16();
} }
ctx.current_version_str = ctx.current_version.ToString(); ctx.current_version_str = ctx.current_version.ToString();
if (!IncrementNewVersion(direction, &ctx)) { if (!IncrementNewVersion(direction, &ctx)) {
LOG(DFATAL) << "Failed to increment version from \"" LOG(DFATAL) << "Failed to increment version from \""
<< original_file.value() << "\""; << original_file.value() << "\"";
return false; return base::string16();
} }
base::Version new_version(base::UTF16ToASCII(ctx.new_version_str)); base::Version new_version(base::UTF16ToASCII(ctx.new_version_str));
GenerateSpecificPEFileVersion(original_file, target_file, new_version); GenerateSpecificPEFileVersion(original_file, target_file, new_version);
return true; return ctx.new_version_str;
} }
bool GenerateSpecificPEFileVersion(const base::FilePath& original_file, bool GenerateSpecificPEFileVersion(const base::FilePath& original_file,
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#ifndef CHROME_INSTALLER_TEST_ALTERNATE_VERSION_GENERATOR_H_ #ifndef CHROME_INSTALLER_TEST_ALTERNATE_VERSION_GENERATOR_H_
#define CHROME_INSTALLER_TEST_ALTERNATE_VERSION_GENERATOR_H_ #define CHROME_INSTALLER_TEST_ALTERNATE_VERSION_GENERATOR_H_
#include <string> #include "base/strings/string16.h"
namespace base { namespace base {
class FilePath; class FilePath;
...@@ -30,16 +30,18 @@ enum Direction { ...@@ -30,16 +30,18 @@ enum Direction {
bool GenerateAlternateVersion(const base::FilePath& original_installer_path, bool GenerateAlternateVersion(const base::FilePath& original_installer_path,
const base::FilePath& target_path, const base::FilePath& target_path,
Direction direction, Direction direction,
std::wstring* original_version, base::string16* original_version,
std::wstring* new_version); base::string16* new_version);
// Given a path to a PEImage in |original_file|, copy that file to // Given a path to a PEImage in |original_file|, copy that file to
// |target_file|, modifying the version of the copy according to |direction|. // |target_file|, modifying the version of the copy according to |direction|.
// Any previous file at |target_file| is clobbered. Returns true on success. // Any previous file at |target_file| is clobbered. On success, returns the
// Note that |target_file| may still be mutated on failure. // version of the generated file. Otherwise, returns an empty string. Note that
bool GenerateAlternatePEFileVersion(const base::FilePath& original_file, // |target_file| may still be mutated on failure.
const base::FilePath& target_file, base::string16 GenerateAlternatePEFileVersion(
Direction direction); const base::FilePath& original_file,
const base::FilePath& target_file,
Direction direction);
// Given a path to a PEImage in |original_file|, copy that file to // Given a path to a PEImage in |original_file|, copy that file to
// |target_file|, modifying the version of the copy according to |version|. // |target_file|, modifying the version of the copy according to |version|.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment