From 8317edb3504120db3ddff0c3270a7ae9a55719f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 29 Jan 2013 01:13:42 +0100 Subject: [PATCH] DriveSetup: Removed (some) knowledge about initialization. * Instead of guessing whether or not to show the InitParamsPanel, the panel will now no longer show itself if the disk system does not have an editor, and silently succeed. * This also fixed a potential crash if the editor could not be created for some reason. * Minor cleanup. --- src/apps/drivesetup/InitParamsPanel.cpp | 15 +++-- src/apps/drivesetup/MainWindow.cpp | 85 ++++++++++++------------- 2 files changed, 49 insertions(+), 51 deletions(-) diff --git a/src/apps/drivesetup/InitParamsPanel.cpp b/src/apps/drivesetup/InitParamsPanel.cpp index 6c2f9de90a..6d03f83fc3 100644 --- a/src/apps/drivesetup/InitParamsPanel.cpp +++ b/src/apps/drivesetup/InitParamsPanel.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2008-2010 Haiku Inc. All rights reserved. + * Copyright 2008-2013 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT license. * * Authors: @@ -104,15 +104,16 @@ InitParamsPanel::InitParamsPanel(BWindow* window, const BString& diskSystem, // put the add-on manager->PutAddOn(addOn); - status_t err = addOn->GetParameterEditor(B_INITIALIZE_PARAMETER_EDITOR, &fEditor); - if (err != B_OK) { + status_t err = addOn->GetParameterEditor(B_INITIALIZE_PARAMETER_EDITOR, + &fEditor); + if (err != B_OK) fEditor = NULL; - } } else { fEditor = NULL; } + if (fEditor == NULL) + return; - // TODO: fEditor should be checked for NULL before adding. SetLayout(new BGroupLayout(B_HORIZONTAL)); const float spacing = be_control_look->DefaultItemSpacing(); AddChild(BGroupLayoutBuilder(B_VERTICAL, spacing) @@ -188,6 +189,10 @@ InitParamsPanel::MessageReceived(BMessage* message) int32 InitParamsPanel::Go(BString& name, BString& parameters) { + // Without an editor, we cannot change anything, anyway + if (fEditor == NULL) + return GO_SUCCESS; + // run the window thread, to get an initial layout of the controls Hide(); Show(); diff --git a/src/apps/drivesetup/MainWindow.cpp b/src/apps/drivesetup/MainWindow.cpp index e6ebcc07e7..2cd67d7d82 100644 --- a/src/apps/drivesetup/MainWindow.cpp +++ b/src/apps/drivesetup/MainWindow.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 Haiku Inc. All rights reserved. + * Copyright 2002-2013 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT license. * * Authors: @@ -7,8 +7,10 @@ * Ithamar R. Adema * Ingo Weinhold * Stephan Aßmus + * Axel Dörfler, axeld@pinc-software.de. */ + #include "MainWindow.h" #include @@ -140,6 +142,38 @@ private: }; +class ModificationPreparer { +public: + ModificationPreparer(BDiskDevice* disk) + : + fDisk(disk), + fModificationStatus(fDisk->PrepareModifications()) + { + } + ~ModificationPreparer() + { + if (fModificationStatus == B_OK) + fDisk->CancelModifications(); + } + status_t ModificationStatus() const + { + return fModificationStatus; + } + status_t CommitModifications() + { + status_t ret = fDisk->CommitModifications(); + if (ret == B_OK) + fModificationStatus = B_ERROR; + + return ret; + } + +private: + BDiskDevice* fDisk; + status_t fModificationStatus; +}; + + enum { MSG_MOUNT_ALL = 'mnta', MSG_MOUNT = 'mnts', @@ -747,38 +781,6 @@ MainWindow::_MountAll() // #pragma mark - -class ModificationPreparer { -public: - ModificationPreparer(BDiskDevice* disk) - : - fDisk(disk), - fModificationStatus(fDisk->PrepareModifications()) - { - } - ~ModificationPreparer() - { - if (fModificationStatus == B_OK) - fDisk->CancelModifications(); - } - status_t ModificationStatus() const - { - return fModificationStatus; - } - status_t CommitModifications() - { - status_t ret = fDisk->CommitModifications(); - if (ret == B_OK) - fModificationStatus = B_ERROR; - - return ret; - } - -private: - BDiskDevice* fDisk; - status_t fModificationStatus; -}; - - void MainWindow::_Initialize(BDiskDevice* disk, partition_id selectedPartition, const BString& diskSystemName) @@ -871,19 +873,10 @@ MainWindow::_Initialize(BDiskDevice* disk, partition_id selectedPartition, BString name; BString parameters; - - // TODO: diskSystem.IsFileSystem() seems like a better fit here? - if (diskSystemName == "Be File System" - || diskSystemName == "NT File System") { - InitParamsPanel* panel = new InitParamsPanel(this, diskSystemName, - partition); - if (panel->Go(name, parameters) == GO_CANCELED) - return; - } else if (diskSystemName == "Intel Partition Map") { - // TODO: parameters? - } else if (diskSystemName == "Intel Extended Partition") { - // TODO: parameters? - } + InitParamsPanel* panel = new InitParamsPanel(this, diskSystemName, + partition); + if (panel->Go(name, parameters) == GO_CANCELED) + return; bool supportsName = diskSystem.SupportsContentName(); BString validatedName(name);