mirror of
https://github.com/cmclark00/retro-imager.git
synced 2025-05-21 17:35:20 +01:00
Qt/QML edition
This commit is contained in:
commit
d7b361ba44
2168 changed files with 721948 additions and 0 deletions
74
dependencies/mountutils/src/worker-eject.cpp
vendored
Normal file
74
dependencies/mountutils/src/worker-eject.cpp
vendored
Normal file
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Copyright 2017 resin.io
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <nan.h>
|
||||
#include "mountutils.hpp"
|
||||
|
||||
class EjectWorker : public Nan::AsyncWorker {
|
||||
public:
|
||||
EjectWorker(Nan::Callback *callback, std::string device)
|
||||
: Nan::AsyncWorker(callback) {
|
||||
device_path = device;
|
||||
}
|
||||
|
||||
~EjectWorker() {}
|
||||
|
||||
void Execute() {
|
||||
MOUNTUTILS_RESULT result = eject_disk(device_path.c_str());
|
||||
|
||||
MountUtilsLog("Eject complete");
|
||||
|
||||
if (result != MOUNTUTILS_SUCCESS) {
|
||||
switch (result) {
|
||||
case MOUNTUTILS_ERROR_ACCESS_DENIED:
|
||||
SetErrorMessage("Eject failed, access denied");
|
||||
break;
|
||||
case MOUNTUTILS_ERROR_INVALID_DRIVE:
|
||||
SetErrorMessage("Eject failed, invalid drive");
|
||||
break;
|
||||
default:
|
||||
SetErrorMessage("Eject failed");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HandleOKCallback() {
|
||||
Nan::HandleScope scope;
|
||||
v8::Local<v8::Value> argv[] = { Nan::Null() };
|
||||
callback->Call(1, argv, async_resource);
|
||||
}
|
||||
|
||||
private:
|
||||
std::string device_path;
|
||||
};
|
||||
|
||||
NAN_METHOD(eject) {
|
||||
if (!info[1]->IsFunction()) {
|
||||
return Nan::ThrowError("Callback must be a function");
|
||||
}
|
||||
|
||||
if (!info[0]->IsString()) {
|
||||
return Nan::ThrowError("Device must be a string");
|
||||
}
|
||||
|
||||
Nan::Utf8String device(Nan::To<v8::String>(info[0]).ToLocalChecked());
|
||||
std::string device_path(*device);
|
||||
Nan::Callback *callback = new Nan::Callback(info[1].As<v8::Function>());
|
||||
|
||||
Nan::AsyncQueueWorker(new EjectWorker(callback, device_path));
|
||||
|
||||
info.GetReturnValue().SetUndefined();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue