Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import std.process;
- import std.stdio;
- import std.range;
- import std.string;
- import std.algorithm.searching;
- import std.format;
- import std.conv;
- import std.file;
- import std.parallelism;
- import core.thread;
- int ddOp(const string logFileName)
- {
- immutable string fileName = "/run/media/user1101/portable_drive/software/os/archlinux-2018.11.01-x86_64.iso";
- immutable string device = "/dev/sdd";
- immutable string command = format("pkexec dd if=/%s of=%s bs=4M status=progress 2>%s && sync",
- fileName, device, logFileName);
- return executeShell(command).status;
- }
- uint parseLog(string logFileName)
- {
- try
- {
- if (!(logFileName.exists))
- return 0;
- auto text = logFileName.readText();
- if (text.splitLines().length == 0)
- return 0;
- if (text.text.splitLines.back.split.front.isNumeric)
- return text.splitLines.back.split.front.to!uint;
- }
- catch (Exception e)
- {
- return 0;
- }
- return 0;
- }
- void main()
- {
- auto logFileName = "/tmp/.dd_op.txt";
- auto invokedd = task!ddOp(logFileName);
- invokedd.executeInNewThread();
- while (!(invokedd.done))
- {
- Thread.sleep(500.msecs);
- writeln(parseLog(logFileName));
- }
- if (logFileName.exists())
- {
- logFileName.remove;
- ddStarted = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement