2 * Copyright 2002-2013 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT license.
6 * Erik Jaesler <ejakowatz@users.sourceforge.net>
7 * Ithamar R. Adema <ithamar@unet.nl>
8 * Stephan Aßmus <superstippi@gmx.de>
11 #include "DriveSetup.h"
12 #include "MainWindow.h"
18 #include <FindDirectory.h>
23 DriveSetup::DriveSetup()
24 : BApplication("application/x-vnd.Haiku-DriveSetup"),
31 DriveSetup::~DriveSetup()
37 DriveSetup::ReadyToRun()
39 fWindow
= new MainWindow();
40 if (_RestoreSettings() != B_OK
)
41 fWindow
->ApplyDefaultSettings();
47 DriveSetup::QuitRequested()
51 if (fWindow
->Lock()) {
64 DriveSetup::_StoreSettings()
66 status_t ret
= B_ERROR
;
67 if (fWindow
->Lock()) {
68 ret
= fWindow
->StoreSettings(&fSettings
);
73 fprintf(stderr
, "failed to store settings: %s\n", strerror(ret
));
78 ret
= _GetSettingsFile(file
, true);
82 ret
= fSettings
.Flatten(&file
);
84 fprintf(stderr
, "failed to flatten settings: %s\n", strerror(ret
));
93 DriveSetup::_RestoreSettings()
96 status_t ret
= _GetSettingsFile(file
, false);
100 ret
= fSettings
.Unflatten(&file
);
102 fprintf(stderr
, "failed to unflatten settings: %s\n", strerror(ret
));
106 ret
= fWindow
->RestoreSettings(&fSettings
);
108 fprintf(stderr
, "failed to restore settings: %s\n", strerror(ret
));
117 DriveSetup::_GetSettingsFile(BFile
& file
, bool forWriting
) const
120 status_t ret
= find_directory(B_USER_SETTINGS_DIRECTORY
, &path
);
122 fprintf(stderr
, "failed to get user settings folder: %s\n",
127 ret
= path
.Append("DriveSetup");
129 fprintf(stderr
, "failed to construct path: %s\n", strerror(ret
));
133 uint32 writeFlags
= B_CREATE_FILE
| B_ERASE_FILE
| B_WRITE_ONLY
;
134 uint32 readFlags
= B_READ_ONLY
;
136 ret
= file
.SetTo(path
.Path(), forWriting
? writeFlags
: readFlags
);
139 // Only inform of an error if the file was supposed to be written.
140 fprintf(stderr
, "failed to init settings file: %s\n",