void ATPClientApp::download(AssetUtils::AssetHash hash) { auto assetClient = DependencyManager::get<AssetClient>(); auto assetRequest = new AssetRequest(hash); connect(assetRequest, &AssetRequest::finished, this, [this](AssetRequest* request) mutable { Q_ASSERT(request->getState() == AssetRequest::Finished); if (request->getError() == AssetRequest::Error::NoError) { QString data = QString::fromUtf8(request->getData()); if (_localOutputFile == "" || _localOutputFile == "-") { QTextStream cout(stdout); cout << data; } else { QFile outputHandle(_localOutputFile); if (outputHandle.open(QIODevice::ReadWrite)) { QTextStream stream( &outputHandle ); stream << data; } else { qDebug() << "couldn't open output file:" << _localOutputFile; } } } request->deleteLater(); finish(0); }); assetRequest->start(); }
void ImageMaker::start() { uint64_t bytesCopied = 0; std::unique_ptr<void, FreeDeleter> buffer(malloc(CHUNK_SIZE)); Handle outputHandle(CreateFile(m_output.c_str(), GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, 0, INVALID_HANDLE_VALUE)); do { DWORD bytesRead = 0; if (ReadFile(m_driveHandle, buffer.get(), CHUNK_SIZE, &bytesRead, nullptr) == FALSE) { if (GetLastError() != ERROR_IO_PENDING) { if (GetLastError() == ERROR_OPERATION_ABORTED) { // Cancelled! break; } throw WinAPIException(GetLastError()); } } DWORD bytesWritten = 0; if (WriteFile(outputHandle.getHandle(), buffer.get(), bytesRead, &bytesWritten, nullptr) == FALSE) { if (GetLastError() != ERROR_IO_PENDING) { if (GetLastError() == ERROR_OPERATION_ABORTED) { // Cancelled! break; } throw WinAPIException(GetLastError()); } } always_assert(bytesRead == bytesWritten, "Mismatch between read & write! No space left?"); bytesCopied += bytesRead; ProgressHandler handler = m_handler; if (handler != nullptr) { handler(bytesCopied, m_totalSize, m_handlerContext); } } while ((!m_shouldHalt.isSignaled()) && (bytesCopied < m_totalSize)); }
Mento::Mento(QObject *parent) : QObject(parent) { if(CocoaInitialize::DefaultApp()->checkRunning()) { initsuccess=false; QMessageBox::warning(0,"Warning","Cocoa Mento 正在运行当中!",QMessageBox::Ok,QMessageBox::Ok); return; } else initsuccess=true; log=new QTextBrowser(); log->setWindowModality(Qt::WindowModal); log->setWindowFlags(Qt::WindowStaysOnTopHint|Qt::CustomizeWindowHint|Qt::WindowCloseButtonHint); log->setGeometry(200,200,400,500); log->setWindowTitle(tr("认证日志")); gt=new Guite(); main=new Menu("Cocoa Mento"); sub=new Menu("Settings"); status=new MenuItem("[状态:正常] 未连接"); connectHandle=new MenuItem("开始认证"); settings=new MenuItem("偏好设置"); about=new MenuItem("关于CocoaMento"); aboutQt=new MenuItem("关于Qt"); help=new MenuItem("使用说明"); exit=new MenuItem("退出"); resetsettings=new MenuItem("重置偏好设置"); logs=new MenuItem("显示日志"); cv=new ConfigView(); cvcontainer=new MenuViewItem("Settings",cv); cv->setPalette(Qt::white); cv->show(); settings->setSubMenu(sub); main->addMenuItem(status); main->addMenuSeparator(); main->addMenuItem(connectHandle); main->addMenuItem(settings); main->addMenuItem(resetsettings); main->addMenuItem(logs); main->addMenuSeparator(); main->addMenuItem(help); main->addMenuItem(about); main->addMenuItem(aboutQt); main->addMenuSeparator(); main->addMenuItem(exit); sub->addMenuItem(cvcontainer); icon=new StatusIcon(); icon->setMenu(main); icon->showIcon(); mainthread=new MentoThread(cv->Config()); connect((QObject*)exit->port,SIGNAL(trigger()),this,SLOT(quitApp())); connect((QObject*)resetsettings->port,SIGNAL(trigger()),cv,SLOT(resetConfig())); connect((QObject*)connectHandle->port,SIGNAL(trigger()),this,SLOT(toggleConnect())); connect((QObject*)logs->port,SIGNAL(trigger()),log,SLOT(show())); connect((QObject*)about->port,SIGNAL(trigger()),gt,SLOT(showAbout())); connect((QObject*)aboutQt->port,SIGNAL(trigger()),this,SLOT(showAboutQt())); connect((QObject*)help->port,SIGNAL(trigger()),gt,SLOT(showHelp())); connect(mainthread,SIGNAL(output(QString)),this,SLOT(outputHandle(QString))); connect(mainthread,SIGNAL(exitSuccess()),this,SLOT(exitHandle())); connect(mainthread,SIGNAL(statusChanged(QString,int)),this,SLOT(statusHandle(QString,int))); connect(mainthread,SIGNAL(error(QString)),this,SLOT(errorHandle(QString))); connect(mainthread,SIGNAL(authError()),this,SLOT(authMento())); connect(mainthread,SIGNAL(noConfig()),this,SLOT(noconfigHandle())); connect(mainthread,SIGNAL(notify(QString)),this,SLOT(notifyHandle(QString))); if(cv->autoConnect()) toggleConnect(); }