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

Side by Side Diff: cloud_print/virtual_driver/win/install/setup.cc

Issue 19052005: Move PathIsWritable, DirectoryExists, ContentsEqual, and TextContentsEqual to the base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <comdef.h> 5 #include <comdef.h>
6 #include <iomanip> 6 #include <iomanip>
7 #include <windows.h> 7 #include <windows.h>
8 #include <winspool.h> 8 #include <winspool.h>
9 #include <setupapi.h> // Must be included after windows.h 9 #include <setupapi.h> // Must be included after windows.h
10 10
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 // We don't support XP service pack 2 or older. 384 // We don't support XP service pack 2 or older.
385 base::win::Version version = base::win::GetVersion(); 385 base::win::Version version = base::win::GetVersion();
386 return (version > base::win::VERSION_XP) || 386 return (version > base::win::VERSION_XP) ||
387 ((version == base::win::VERSION_XP) && 387 ((version == base::win::VERSION_XP) &&
388 (base::win::OSInfo::GetInstance()->service_pack().major >= 3)); 388 (base::win::OSInfo::GetInstance()->service_pack().major >= 3));
389 } 389 }
390 390
391 HRESULT RegisterVirtualDriver(const base::FilePath& install_path) { 391 HRESULT RegisterVirtualDriver(const base::FilePath& install_path) {
392 HRESULT result = S_OK; 392 HRESULT result = S_OK;
393 393
394 DCHECK(file_util::DirectoryExists(install_path)); 394 DCHECK(base::DirectoryExists(install_path));
395 if (!IsOSSupported()) { 395 if (!IsOSSupported()) {
396 LOG(ERROR) << "Requires XP SP3 or later."; 396 LOG(ERROR) << "Requires XP SP3 or later.";
397 return HRESULT_FROM_WIN32(ERROR_OLD_WIN_VERSION); 397 return HRESULT_FROM_WIN32(ERROR_OLD_WIN_VERSION);
398 } 398 }
399 399
400 result = InstallDriver(install_path); 400 result = InstallDriver(install_path);
401 if (FAILED(result)) { 401 if (FAILED(result)) {
402 LOG(ERROR) << "Unable to install driver."; 402 LOG(ERROR) << "Unable to install driver.";
403 return result; 403 return result;
404 } 404 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 HRESULT DoRegister(const base::FilePath& install_path) { 470 HRESULT DoRegister(const base::FilePath& install_path) {
471 HRESULT result = UnregisterVirtualDriver(); 471 HRESULT result = UnregisterVirtualDriver();
472 if (FAILED(result)) 472 if (FAILED(result))
473 return result; 473 return result;
474 return RegisterVirtualDriver(install_path); 474 return RegisterVirtualDriver(install_path);
475 } 475 }
476 476
477 HRESULT DoDelete(const base::FilePath& install_path) { 477 HRESULT DoDelete(const base::FilePath& install_path) {
478 if (install_path.value().empty()) 478 if (install_path.value().empty())
479 return E_INVALIDARG; 479 return E_INVALIDARG;
480 if (!file_util::DirectoryExists(install_path)) 480 if (!base::DirectoryExists(install_path))
481 return S_FALSE; 481 return S_FALSE;
482 Sleep(5000); // Give parent some time to exit. 482 Sleep(5000); // Give parent some time to exit.
483 return base::Delete(install_path, true) ? S_OK : E_FAIL; 483 return base::Delete(install_path, true) ? S_OK : E_FAIL;
484 } 484 }
485 485
486 HRESULT DoInstall(const base::FilePath& install_path) { 486 HRESULT DoInstall(const base::FilePath& install_path) {
487 HRESULT result = UnregisterVirtualDriver(); 487 HRESULT result = UnregisterVirtualDriver();
488 if (FAILED(result)) { 488 if (FAILED(result)) {
489 LOG(ERROR) << "Unable to unregister."; 489 LOG(ERROR) << "Unable to unregister.";
490 return result; 490 return result;
491 } 491 }
492 base::FilePath old_install_path = GetInstallLocation(kUninstallId); 492 base::FilePath old_install_path = GetInstallLocation(kUninstallId);
493 if (!old_install_path.value().empty() && 493 if (!old_install_path.value().empty() &&
494 install_path != old_install_path) { 494 install_path != old_install_path) {
495 if (file_util::DirectoryExists(old_install_path)) 495 if (base::DirectoryExists(old_install_path))
496 base::Delete(old_install_path, true); 496 base::Delete(old_install_path, true);
497 } 497 }
498 CreateUninstallKey(kUninstallId, LoadLocalString(IDS_DRIVER_NAME), 498 CreateUninstallKey(kUninstallId, LoadLocalString(IDS_DRIVER_NAME),
499 kUninstallSwitch); 499 kUninstallSwitch);
500 result = RegisterVirtualDriver(install_path); 500 result = RegisterVirtualDriver(install_path);
501 if (FAILED(result)) 501 if (FAILED(result))
502 return result; 502 return result;
503 SetGoogleUpdateKeys(kGoogleUpdateProductId, kNameValue); 503 SetGoogleUpdateKeys(kGoogleUpdateProductId, kNameValue);
504 return result; 504 return result;
505 } 505 }
506 506
507 HRESULT ExecuteCommands() { 507 HRESULT ExecuteCommands() {
508 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 508 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
509 509
510 base::FilePath exe_path; 510 base::FilePath exe_path;
511 if (FAILED(PathService::Get(base::DIR_EXE, &exe_path)) || 511 if (FAILED(PathService::Get(base::DIR_EXE, &exe_path)) ||
512 !file_util::DirectoryExists(exe_path)) { 512 !base::DirectoryExists(exe_path)) {
513 return HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND); 513 return HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND);
514 } 514 }
515 515
516 if (command_line.HasSwitch(kDelete)) { 516 if (command_line.HasSwitch(kDelete)) {
517 return DoDelete(command_line.GetSwitchValuePath(kDelete)); 517 return DoDelete(command_line.GetSwitchValuePath(kDelete));
518 } else if (command_line.HasSwitch(kUninstallSwitch)) { 518 } else if (command_line.HasSwitch(kUninstallSwitch)) {
519 return DoUninstall(); 519 return DoUninstall();
520 } else if (command_line.HasSwitch(kInstallSwitch)) { 520 } else if (command_line.HasSwitch(kInstallSwitch)) {
521 return DoInstall(exe_path); 521 return DoInstall(exe_path);
522 } else if (command_line.HasSwitch(kUnregisterSwitch)) { 522 } else if (command_line.HasSwitch(kUnregisterSwitch)) {
(...skipping 20 matching lines...) Expand all
543 LOG(INFO) << _com_error(retval).ErrorMessage() << " HRESULT=0x" << 543 LOG(INFO) << _com_error(retval).ErrorMessage() << " HRESULT=0x" <<
544 std::setbase(16) << retval; 544 std::setbase(16) << retval;
545 545
546 // Installer is silent by default as required by Google Update. 546 // Installer is silent by default as required by Google Update.
547 if (CommandLine::ForCurrentProcess()->HasSwitch("verbose")) { 547 if (CommandLine::ForCurrentProcess()->HasSwitch("verbose")) {
548 cloud_print::DisplayWindowsMessage(NULL, retval, 548 cloud_print::DisplayWindowsMessage(NULL, retval,
549 cloud_print::LoadLocalString(IDS_DRIVER_NAME)); 549 cloud_print::LoadLocalString(IDS_DRIVER_NAME));
550 } 550 }
551 return retval; 551 return retval;
552 } 552 }
OLDNEW
« no previous file with comments | « chrome_frame/test/test_with_web_server.cc ('k') | cloud_print/virtual_driver/win/port_monitor/port_monitor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698