mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-08 06:32:55 -04:00
fixed handling of incoming rscollection files
This commit is contained in:
parent
142a8e2503
commit
eccfc7ba71
5 changed files with 48 additions and 21 deletions
|
@ -1254,21 +1254,23 @@ void MainWindow::doQuit()
|
||||||
rApp->quit();
|
rApp->quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method parses arguments passed by another process. All arguments
|
// This method parses arguments passed by the operating system. All arguments
|
||||||
// except -r, -f, -o and lists of rscollection files and rslinks are discarded.
|
// except -r, -f, -o and lists of rscollection files and rslinks are discarded.
|
||||||
//
|
//
|
||||||
void MainWindow::receiveNewArgs(QStringList args)
|
void MainWindow::receiveNewArgs(QStringList args)
|
||||||
{
|
{
|
||||||
QString arg, argl, value;
|
RsInfo() << "Received new arguments from operating system call.";
|
||||||
std::vector<const char *> argv;
|
|
||||||
|
std::string argstring = RsApplication::applicationFilePath().toStdString() ;
|
||||||
|
|
||||||
for(auto l:args)
|
for(auto l:args)
|
||||||
argv.push_back((const char *)l.data());
|
argstring += " " + l.toStdString();
|
||||||
|
|
||||||
// This class does all the job at once: validate arguments, and parses them.
|
// This class does all the job at once: validate arguments, and parses them.
|
||||||
|
|
||||||
std::vector<std::string> links_and_files;
|
std::vector<std::string> links_and_files;
|
||||||
|
|
||||||
argstream as(argv.size(),const_cast<char **>(argv.data()));
|
argstream as(argstring.c_str());
|
||||||
|
|
||||||
QString omValues = QString(";full;noturtle;gaming;minimal;");
|
QString omValues = QString(";full;noturtle;gaming;minimal;");
|
||||||
std::string opModeStr;
|
std::string opModeStr;
|
||||||
|
@ -1291,6 +1293,8 @@ void MainWindow::receiveNewArgs(QStringList args)
|
||||||
QString opmode = QString::fromStdString(opModeStr).toLower();
|
QString opmode = QString::fromStdString(opModeStr).toLower();
|
||||||
//RsApplication::setOpMode(opModeStr.toLower()); // Do we need this??
|
//RsApplication::setOpMode(opModeStr.toLower()); // Do we need this??
|
||||||
|
|
||||||
|
RsInfo() << "Setting new operating mode to \"" << opmode.toStdString() << "\"";
|
||||||
|
|
||||||
if (opmode == "noturtle")
|
if (opmode == "noturtle")
|
||||||
opModeStatus->setCurrentIndex(static_cast<typename std::underlying_type<RsOpMode>::type>(RsOpMode::NOTURTLE) - 1);
|
opModeStatus->setCurrentIndex(static_cast<typename std::underlying_type<RsOpMode>::type>(RsOpMode::NOTURTLE) - 1);
|
||||||
else if (opmode == "gaming")
|
else if (opmode == "gaming")
|
||||||
|
@ -1704,6 +1708,12 @@ void MainWindow::openRsCollection(const QString &filename)
|
||||||
if (qinfo.exists()) {
|
if (qinfo.exists()) {
|
||||||
if (qinfo.absoluteFilePath().endsWith(RsCollection::ExtensionString)) {
|
if (qinfo.absoluteFilePath().endsWith(RsCollection::ExtensionString)) {
|
||||||
RsCollection collection;
|
RsCollection collection;
|
||||||
|
|
||||||
|
if(!collection.load(filename))
|
||||||
|
{
|
||||||
|
RsErr() << "Could not open Rscollection file " << filename.toStdString();
|
||||||
|
return;
|
||||||
|
}
|
||||||
collection.downloadFiles();
|
collection.downloadFiles();
|
||||||
//collection.openColl(qinfo.absoluteFilePath());
|
//collection.openColl(qinfo.absoluteFilePath());
|
||||||
}
|
}
|
||||||
|
|
|
@ -385,7 +385,7 @@ bool RsCollection::checkFile(const QString& fileName, bool showError)
|
||||||
|
|
||||||
//std::cerr << "n==" << n <<" Checking string " << std::string(current,n+1) << " c = " << std::hex << (int)c << std::dec << std::endl;
|
//std::cerr << "n==" << n <<" Checking string " << std::string(current,n+1) << " c = " << std::hex << (int)c << std::dec << std::endl;
|
||||||
|
|
||||||
for(uint i=0;i<bad_strings.size();++i)
|
for(uint i=0;i<bad_strings.size();++i)
|
||||||
if(std::string(current,bad_strings[i].length()) == bad_strings[i])
|
if(std::string(current,bad_strings[i].length()) == bad_strings[i])
|
||||||
{
|
{
|
||||||
showErrorBox(file.fileName(), QApplication::translate("RsCollectionFile", "This file contains the string \"%1\" and is therefore an invalid collection file. \n\nIf you believe it is correct, remove the corresponding line from the file and re-open it with Retroshare.").arg(bad_strings[i].c_str()));
|
showErrorBox(file.fileName(), QApplication::translate("RsCollectionFile", "This file contains the string \"%1\" and is therefore an invalid collection file. \n\nIf you believe it is correct, remove the corresponding line from the file and re-open it with Retroshare.").arg(bad_strings[i].c_str()));
|
||||||
|
@ -394,7 +394,7 @@ bool RsCollection::checkFile(const QString& fileName, bool showError)
|
||||||
//std::cerr << "Bad string detected" << std::endl;
|
//std::cerr << "Bad string detected" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(file.atEnd())
|
if(file.atEnd())
|
||||||
n-- ;
|
n-- ;
|
||||||
else if(n < max_size)
|
else if(n < max_size)
|
||||||
++n ;
|
++n ;
|
||||||
|
|
|
@ -149,7 +149,7 @@
|
||||||
<string><html><head/><body><p>When checked, this retroshare instance will accept calls by your operating system to open Retroshare collection files, and download links.</p></body></html></string>
|
<string><html><head/><body><p>When checked, this retroshare instance will accept calls by your operating system to open Retroshare collection files, and download links.</p></body></html></string>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Use Local Server to get new arguments.</string>
|
<string>Accept operating systems calls</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="checked">
|
<property name="checked">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
|
|
|
@ -145,6 +145,7 @@ static bool notifyRunningInstance()
|
||||||
// Connect to the Local Server of the main process to notify it
|
// Connect to the Local Server of the main process to notify it
|
||||||
// that a new process had been started
|
// that a new process had been started
|
||||||
|
|
||||||
|
RsInfo() << "Trying to contact running instance through socket \"" << TARGET << "\"";
|
||||||
QLocalSocket localSocket;
|
QLocalSocket localSocket;
|
||||||
localSocket.connectToServer(QString(TARGET));
|
localSocket.connectToServer(QString(TARGET));
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
|
@ -240,6 +240,17 @@ RsApplication::RsApplication(const RsGUIConfigOptions& conf)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// So we start a Local Server to listen for connections from new process
|
||||||
|
localServer= new QLocalServer();
|
||||||
|
QObject::connect(localServer, SIGNAL(newConnection()), this, SLOT(slotConnectionEstablished()));
|
||||||
|
updateLocalServer();
|
||||||
|
|
||||||
|
// clear out any old arguments (race condition?)
|
||||||
|
QSharedMemory newArgs;
|
||||||
|
newArgs.setKey(QString(TARGET) + "_newArgs");
|
||||||
|
if(newArgs.attach(QSharedMemory::ReadWrite))
|
||||||
|
newArgs.detach();
|
||||||
|
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK (5, 0, 0)
|
#if QT_VERSION >= QT_VERSION_CHECK (5, 0, 0)
|
||||||
qInstallMessageHandler(qt_msg_handler);
|
qInstallMessageHandler(qt_msg_handler);
|
||||||
#else
|
#else
|
||||||
|
@ -344,22 +355,27 @@ void RsApplication::slotConnectionEstablished()
|
||||||
socket->close();
|
socket->close();
|
||||||
delete socket;
|
delete socket;
|
||||||
|
|
||||||
QBuffer buffer;
|
if(newArgs.error())
|
||||||
QDataStream in(&buffer);
|
{
|
||||||
QStringList args;
|
RsErr() << "Something when wrong in receiving arguments from operating system: " << newArgs.errorString().toStdString() ;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
QBuffer buffer;
|
||||||
|
QDataStream in(&buffer);
|
||||||
|
QStringList args;
|
||||||
|
|
||||||
newArgs.lock();
|
newArgs.lock();
|
||||||
buffer.setData((char*)newArgs.constData(), newArgs.size());
|
buffer.setData((char*)newArgs.constData(), newArgs.size());
|
||||||
buffer.open(QBuffer::ReadOnly);
|
buffer.open(QBuffer::ReadOnly);
|
||||||
in >> args;
|
in >> args;
|
||||||
newArgs.unlock();
|
newArgs.unlock();
|
||||||
newArgs.detach();
|
newArgs.detach();
|
||||||
|
|
||||||
emit newArgsReceived(args);
|
emit newArgsReceived(args);
|
||||||
while (!args.empty())
|
while (!args.empty())
|
||||||
{
|
{
|
||||||
std::cerr << "RsApplication::slotConnectionEstablished args:" << QString(args.takeFirst()).toStdString() << std::endl;
|
std::cerr << "RsApplication::slotConnectionEstablished args:" << QString(args.takeFirst()).toStdString() << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString RsApplication::retroshareVersion(bool) { return RS_HUMAN_READABLE_VERSION; }
|
QString RsApplication::retroshareVersion(bool) { return RS_HUMAN_READABLE_VERSION; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue