void QmitkXnatEditor::InternalFileDownload(const QModelIndex& index) { QVariant variant = m_ListModel->data(index, Qt::UserRole); if (variant.isValid()) { ctkXnatFile* file = dynamic_cast<ctkXnatFile*>(variant.value<ctkXnatObject*>()); if (file != NULL) { // Testing if the file exists QDir downDir(m_DownloadPath); if (downDir.exists(file->property("Name"))) { MITK_INFO << "File exists already!"; return; } if (file->property("collection") == QString("DICOM")) { ctkXnatObject* parent = file->parent(); QString filePath = m_DownloadPath + parent->property("label") + ".zip"; parent->download(filePath); std::ifstream in(filePath.toStdString().c_str(), std::ios::binary); poco_assert(in); // decompress to XNAT_DOWNLOAD dir Poco::Zip::Decompress dec(in, Poco::Path(m_DownloadPath.toStdString())); dec.decompressAllFiles(); in.close(); QFile::remove(filePath); } else { MITK_INFO << "Download started ..."; MITK_INFO << "..."; QString name = file->property("Name"); QString filePath = m_DownloadPath + name; file->download(filePath); // Testing if the file exists QDir downDir(m_DownloadPath); if (downDir.exists(name)) { MITK_INFO << "Download of " << file->name().toStdString() << " was completed!"; } else { MITK_INFO << "Download of " << file->name().toStdString() << " failed!"; } } } else { MITK_INFO << "Selection was not a file!"; } } }
void downDir(int fd_client, char *dir_name) { DIR *pdir = opendir(dir_name); if(pdir == NULL){ perror("opedir!\n"); send(fd_client, "over", 8, 0); return ; } chdir(dir_name); struct dirent* mydirent; struct stat mystat; while((mydirent = readdir(pdir)) != NULL){ send(fd_client, "continue", 8, 0); stat(mydirent->d_name, &mystat); if(S_ISDIR(mystat.st_mode)){ if(strncmp(mydirent->d_name, ".", 1) == 0){ send(fd_client, "nodir", 8, 0); continue; } else{ send(fd_client, "dir", 8, 0); send(fd_client, mydirent->d_name, sizeof(mydirent->d_name), 0); //printf("%s: %d\n", mydirent->d_name, sizeof(mydirent->d_name)); downDir(fd_client, mydirent->d_name); } } else{ downFile(fd_client, (mydirent->d_name)); } } send(fd_client, "over", 8, 0); chdir(".."); closedir(pdir); }
//do_gets void do_gets(int fd_client, int role) { if(role == 3){ return ; } else{ struct stat mystat; int send_len; char file_name[256] = "0"; memset(&file_name, 0 , 256); recv_buf(fd_client, (char*)&send_len, 4); recv_buf(fd_client, file_name, send_len); file_name[strlen(file_name) - 1] = '\0'; lstat(file_name, &mystat); if(S_ISDIR(mystat.st_mode)){ send(fd_client, "dir", 8, 0); downDir(fd_client, file_name); } else{ downFile(fd_client, file_name); } printf("send complient!\n"); } }
void QmitkXnatEditor::InternalFileDownload(const QModelIndex& index) { QVariant variant = m_ListModel->data(index, Qt::UserRole); if ( variant.isValid() ) { ctkXnatFile* file = dynamic_cast<ctkXnatFile*>(variant.value<ctkXnatObject*>()); if (file != NULL) { MITK_INFO << "Download started ..."; MITK_INFO << "..."; QString filePath = m_DownloadPath + file->id(); file->download(filePath); // Testing if the file exists QDir downDir(m_DownloadPath); if( downDir.exists(file->id()) ) { MITK_INFO << "Download of " << file->id().toStdString() << " was completed!"; } else { MITK_INFO << "Download of " << file->id().toStdString() << " failed!"; } } else { MITK_INFO << "Selection was not a file!"; } } }
void QmitkXnatEditor::DownloadResource() { if (!m_Controls.treeView->selectionModel()->hasSelection()) return; const QModelIndex index = m_Controls.treeView->selectionModel()->currentIndex(); QVariant variant = m_ListModel->data(index, Qt::UserRole); if ( variant.isValid() ) { ctkXnatScanFolder* resource = dynamic_cast<ctkXnatScanFolder*>(variant.value<ctkXnatObject*>()); if (resource != NULL) { MITK_INFO << "Download started ..."; MITK_INFO << "..."; QString resourcePath = m_DownloadPath + resource->id() + ".zip"; resource->download(resourcePath); // Testing if the path exists QDir downDir(m_DownloadPath); if( downDir.exists(resource->id() + ".zip") ) { MITK_INFO << "Download of " << resource->id().toStdString() << ".zip was completed!"; } else { MITK_INFO << "Download of " << resource->id().toStdString() << ".zip failed!"; } } else { MITK_INFO << "Selection was not a resource folder!"; } } }
void QmitkXnatEditor::DownloadResource() { if (!m_Controls.listView->selectionModel()->hasSelection()) return; const QModelIndex index = m_Controls.listView->selectionModel()->currentIndex(); QVariant variant = m_ListModel->data(index, Qt::UserRole); if (variant.isValid()) { ctkXnatObject* resource = variant.value<ctkXnatObject*>(); if (dynamic_cast<ctkXnatFile*>(resource) == NULL) { MITK_INFO << "Download started ..."; MITK_INFO << "..."; QString resourceName = m_ListModel->data(index, Qt::DisplayRole).toString(); QString resourcePath = m_DownloadPath + resourceName + ".zip"; resource->download(resourcePath); // Testing if the path exists QDir downDir(m_DownloadPath); if (downDir.exists(resourceName + ".zip")) { MITK_INFO << "Download of " << resourceName.toStdString() << ".zip was completed!"; } else { MITK_INFO << "Download of " << resourceName.toStdString() << ".zip failed!"; } } else { InternalFileDownload(index); } } }