mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-25 09:11:28 -05:00
Merged revision 7165 from v0.5.5
Create a hard link for preview on Windows with the real name of the downloading file git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7309 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
4569c21cb0
commit
07e57836bf
@ -19,10 +19,6 @@
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <QMenu>
|
||||
#include <QInputDialog>
|
||||
#include <QFileDialog>
|
||||
@ -55,6 +51,7 @@
|
||||
#include <gui/common/RsCollectionFile.h>
|
||||
#include "TransferUserNotify.h"
|
||||
#include "util/QtVersion.h"
|
||||
#include "util/RsFile.h"
|
||||
|
||||
#include <retroshare/rsfiles.h>
|
||||
#include <retroshare/rspeers.h>
|
||||
@ -1718,8 +1715,10 @@ void TransfersDialog::previewTransfer()
|
||||
break;
|
||||
}
|
||||
|
||||
QFileInfo fileNameInfo(QString::fromUtf8(info.fname.c_str()));
|
||||
|
||||
/* check if the file is a media file */
|
||||
if (!misc::isPreviewable(QFileInfo(QString::fromUtf8(info.fname.c_str())).suffix())) return;
|
||||
if (!misc::isPreviewable(fileNameInfo.suffix())) return;
|
||||
|
||||
/* make path for downloaded or downloading files */
|
||||
QFileInfo fileInfo;
|
||||
@ -1728,8 +1727,16 @@ void TransfersDialog::previewTransfer()
|
||||
} else {
|
||||
fileInfo = QFileInfo(QString::fromUtf8(rsFiles->getPartialsDirectory().c_str()), QString::fromUtf8(info.hash.toStdString().c_str()));
|
||||
|
||||
QString linkName = QFileInfo(QDir::temp(), QString::fromUtf8(info.fname.c_str())).absoluteFilePath();
|
||||
if (QFile::link(fileInfo.absoluteFilePath(), linkName)) {
|
||||
QDir temp;
|
||||
#ifdef WINDOWS_SYS
|
||||
/* the symbolic link must be created on the same drive like the real file, use partial directory */
|
||||
temp = fileInfo.absoluteDir();
|
||||
#else
|
||||
temp = QDir::temp();
|
||||
#endif
|
||||
|
||||
QString linkName = QFileInfo(temp, fileNameInfo.fileName()).absoluteFilePath();
|
||||
if (RsFile::CreateLink(fileInfo.absoluteFilePath(), linkName)) {
|
||||
fileInfo.setFile(linkName);
|
||||
} else {
|
||||
std::cerr << "previewTransfer(): can't create link for file " << fileInfo.absoluteFilePath().toStdString() << std::endl;
|
||||
@ -1752,7 +1759,17 @@ void TransfersDialog::previewTransfer()
|
||||
/* wait for the file to open then remove the link */
|
||||
QMessageBox::information(this, tr("File preview"), tr("Click OK when program terminates!"));
|
||||
}
|
||||
QFile::remove(fileInfo.absoluteFilePath());
|
||||
/* try to delete the preview file */
|
||||
forever {
|
||||
if (QFile::remove(fileInfo.absoluteFilePath())) {
|
||||
/* preview file could be removed */
|
||||
break;
|
||||
}
|
||||
/* ask user to try it again */
|
||||
if (QMessageBox::question(this, tr("File preview"), QString("%1\n\n%2\n\n%3").arg(tr("Could not delete preview file"), fileInfo.absoluteFilePath(), tr("Try it again?")), QMessageBox::Yes, QMessageBox::No) == QMessageBox::No) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13891,6 +13891,14 @@ Try to be patient!</source>
|
||||
<source> <h1><img width="32" src=":/images/64px_help.png">&nbsp;&nbsp;File Transfer</h1> <p>Retroshare brings two ways of transferring files: direct transfers from your friends, and distant anonymous tunnelled transfers. In addition, file transfer is multi-source and allows swarming (you can be a source while downloading)</p> <p>You can share files using the <img src=":/images/directoryadd_24x24_shadow.png" width=16 /> icon from the left side bar. These files will be listed in the My Files tab. You can decide for each friend group whether they can or not see these files in their Friends Files tab</p> <p>The search tab reports files from your friends' file lists, and distant files that can be reached anonymously using the multi-hop tunnelling system.</p> </source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Could not delete preview file</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Try it again?</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>TreeStyle_RDM</name>
|
||||
|
@ -364,6 +364,7 @@ HEADERS += rshare.h \
|
||||
util/HandleRichText.h \
|
||||
util/ObjectPainter.h \
|
||||
util/QtVersion.h \
|
||||
util/RsFile.h \
|
||||
gui/bwgraph/bwgraph.h \
|
||||
gui/profile/ProfileWidget.h \
|
||||
gui/profile/ProfileManager.h \
|
||||
@ -683,6 +684,7 @@ SOURCES += main.cpp \
|
||||
util/misc.cpp \
|
||||
util/HandleRichText.cpp \
|
||||
util/ObjectPainter.cpp \
|
||||
util/RsFile.cpp \
|
||||
gui/bwgraph/bwgraph.cpp \
|
||||
gui/profile/ProfileWidget.cpp \
|
||||
gui/profile/StatusMessage.cpp \
|
||||
|
58
retroshare-gui/src/util/RsFile.cpp
Normal file
58
retroshare-gui/src/util/RsFile.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
/****************************************************************
|
||||
* This file is distributed under the following license:
|
||||
*
|
||||
* Copyright (c) 2014, RetroShare Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#include "RsFile.h"
|
||||
|
||||
#ifdef WINDOWS_SYS
|
||||
#include <QDir>
|
||||
#include <windows.h>
|
||||
|
||||
#ifndef __MINGW64_VERSION_MAJOR
|
||||
#include <QLibrary>
|
||||
typedef BOOL (*lpCreateHardLinkW)(LPWSTR lpFileName, LPWSTR lpExisitingFileName, LPSECURITY_ATTRIBUTES lpSecurityAttributes);
|
||||
#endif
|
||||
|
||||
#else
|
||||
#include <QFile>
|
||||
#endif
|
||||
|
||||
bool RsFile::CreateLink(const QString &targetFileName, const QString &symbolicFileName)
|
||||
{
|
||||
#ifdef WINDOWS_SYS
|
||||
#ifdef __MINGW64_VERSION_MAJOR
|
||||
return CreateHardLink((WCHAR*) QDir::toNativeSeparators(symbolicFileName).toStdWString().c_str(), (WCHAR*) QDir::toNativeSeparators(targetFileName).toStdWString().c_str(), NULL);
|
||||
#else
|
||||
QLibrary library("kernel32");
|
||||
if (!library.load()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
lpCreateHardLinkW pCreateHardLinkW = (lpCreateHardLinkW) library.resolve("CreateHardLinkW");
|
||||
if (!pCreateHardLinkW) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return pCreateHardLinkW((WCHAR*) QDir::toNativeSeparators(symbolicFileName).toStdWString().c_str(), (WCHAR*) QDir::toNativeSeparators(targetFileName).toStdWString().c_str(), NULL);
|
||||
#endif
|
||||
#else
|
||||
return QFile::link(targetFileName, symbolicFileName);
|
||||
#endif
|
||||
}
|
33
retroshare-gui/src/util/RsFile.h
Normal file
33
retroshare-gui/src/util/RsFile.h
Normal file
@ -0,0 +1,33 @@
|
||||
/****************************************************************
|
||||
* This file is distributed under the following license:
|
||||
*
|
||||
* Copyright (c) 2014, RetroShare Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#ifndef _RSFILE_H
|
||||
#define _RSFILE_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
class RsFile
|
||||
{
|
||||
public:
|
||||
static bool CreateLink(const QString &targetFileName, const QString &symbolicFileName);
|
||||
};
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user