DriveSetup: show status of disk image operations
Change-Id: Ic31bca9f54599e0df0fef461e9da3c3c51ab53ff Reviewed-on: https://review.haiku-os.org/c/haiku/+/10217 Tested-by: Commit checker robot <[email protected]> Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
@@ -409,6 +409,8 @@ MainWindow::~MainWindow()
|
|||||||
delete fRegisterFilePanel;
|
delete fRegisterFilePanel;
|
||||||
delete fReadImageFilePanel;
|
delete fReadImageFilePanel;
|
||||||
delete fWriteImageFilePanel;
|
delete fWriteImageFilePanel;
|
||||||
|
|
||||||
|
delete fNotification;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -628,11 +630,14 @@ MainWindow::MessageReceived(BMessage* message)
|
|||||||
case MSG_COMPLETE:
|
case MSG_COMPLETE:
|
||||||
{
|
{
|
||||||
const char* status = "";
|
const char* status = "";
|
||||||
|
const char* jobid = "";
|
||||||
|
|
||||||
message->FindString("status", &status);
|
message->FindString("status", &status);
|
||||||
|
message->FindString("jobid", &jobid);
|
||||||
|
|
||||||
fNotification->SetTitle(BString(B_TRANSLATE("Disk image")));
|
fNotification->SetTitle(BString(B_TRANSLATE("Disk image")));
|
||||||
fNotification->SetContent(BString(status));
|
fNotification->SetContent(BString(status));
|
||||||
|
fNotification->SetMessageID(BString(jobid));
|
||||||
fNotification->Send();
|
fNotification->Send();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -942,30 +947,9 @@ MainWindow::SaveDiskImage(void* data)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t bufsize = 1024*1024;
|
_WriteDiskImage(messenger, source, target, targetpath,
|
||||||
off_t sourcesize, targetsize;
|
BString(B_TRANSLATE("Creating disk image")),
|
||||||
ssize_t targetbytes = 0;
|
BString(B_TRANSLATE("Disk image successfully created.")));
|
||||||
|
|
||||||
source.GetSize(&sourcesize);
|
|
||||||
|
|
||||||
char* buffer = (char*)malloc(bufsize);
|
|
||||||
while (true) {
|
|
||||||
ssize_t bytes = source.Read(buffer, bufsize);
|
|
||||||
|
|
||||||
if (bytes > 0) {
|
|
||||||
target.Write(buffer, (size_t)bytes);
|
|
||||||
target.GetSize(&targetsize);
|
|
||||||
|
|
||||||
targetbytes += bytes;
|
|
||||||
} else
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
free(buffer);
|
|
||||||
|
|
||||||
BMessage message(MSG_COMPLETE);
|
|
||||||
message.AddString("status",
|
|
||||||
B_TRANSLATE("Disk image successfully created."));
|
|
||||||
messenger.SendMessage(&message);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1012,12 +996,32 @@ MainWindow::WriteDiskImage(void* data)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_WriteDiskImage(messenger, source, target, targetpath,
|
||||||
|
BString(B_TRANSLATE("Writing image to disk")),
|
||||||
|
BString(B_TRANSLATE("Disk image successfully written to the target.")));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
MainWindow::_WriteDiskImage(BMessenger messenger, BFile source, BFile target,
|
||||||
|
const char* targetpath, BString title, BString status)
|
||||||
|
{
|
||||||
size_t bufsize = 1024 * 1024;
|
size_t bufsize = 1024 * 1024;
|
||||||
off_t sourcesize;
|
off_t sourcesize;
|
||||||
ssize_t targetbytes = 0;
|
ssize_t targetbytes = 0;
|
||||||
|
|
||||||
source.GetSize(&sourcesize);
|
source.GetSize(&sourcesize);
|
||||||
|
|
||||||
|
char maximumBuffer[16], currentBuffer[16];
|
||||||
|
BString statusprogress;
|
||||||
|
|
||||||
|
BNotification progress(B_PROGRESS_NOTIFICATION);
|
||||||
|
progress.SetGroup(BString(B_TRANSLATE_SYSTEM_NAME("DriveSetup")));
|
||||||
|
progress.SetMessageID(BString(targetpath));
|
||||||
|
progress.SetTitle(title);
|
||||||
|
|
||||||
char* buffer = (char*)malloc(bufsize);
|
char* buffer = (char*)malloc(bufsize);
|
||||||
while (true) {
|
while (true) {
|
||||||
ssize_t bytes = source.Read(buffer, bufsize);
|
ssize_t bytes = source.Read(buffer, bufsize);
|
||||||
@@ -1026,17 +1030,23 @@ MainWindow::WriteDiskImage(void* data)
|
|||||||
target.Write(buffer, (size_t)bytes);
|
target.Write(buffer, (size_t)bytes);
|
||||||
|
|
||||||
targetbytes += bytes;
|
targetbytes += bytes;
|
||||||
|
|
||||||
|
statusprogress.SetToFormat("%s: %s / %s", targetpath,
|
||||||
|
string_for_size(targetbytes, currentBuffer, 16),
|
||||||
|
string_for_size(sourcesize, maximumBuffer, 16));
|
||||||
|
|
||||||
|
progress.SetContent(statusprogress);
|
||||||
|
progress.SetProgress((float)targetbytes / sourcesize);
|
||||||
|
progress.Send();
|
||||||
} else
|
} else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
|
||||||
BMessage message(MSG_COMPLETE);
|
BMessage message(MSG_COMPLETE);
|
||||||
message.AddString("status",
|
message.AddString("status", status);
|
||||||
B_TRANSLATE("Disk image successfully written to the target."));
|
message.AddString("jobid", targetpath);
|
||||||
messenger.SendMessage(&message);
|
messenger.SendMessage(&message);
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,11 @@ public:
|
|||||||
static int32 WriteDiskImage(void* data);
|
static int32 WriteDiskImage(void* data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static void _WriteDiskImage(BMessenger messenger,
|
||||||
|
BFile source, BFile target,
|
||||||
|
const char* targetpath,
|
||||||
|
BString title, BString status);
|
||||||
|
|
||||||
void _ScanDrives();
|
void _ScanDrives();
|
||||||
|
|
||||||
void _AdaptToSelectedPartition();
|
void _AdaptToSelectedPartition();
|
||||||
|
|||||||
Reference in New Issue
Block a user