mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
fixed handling of incoming rscollection files
This commit is contained in:
parent
142a8e2503
commit
eccfc7ba71
@ -1254,21 +1254,23 @@ void MainWindow::doQuit()
|
||||
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.
|
||||
//
|
||||
void MainWindow::receiveNewArgs(QStringList args)
|
||||
{
|
||||
QString arg, argl, value;
|
||||
std::vector<const char *> argv;
|
||||
RsInfo() << "Received new arguments from operating system call.";
|
||||
|
||||
std::string argstring = RsApplication::applicationFilePath().toStdString() ;
|
||||
|
||||
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.
|
||||
|
||||
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;");
|
||||
std::string opModeStr;
|
||||
@ -1291,6 +1293,8 @@ void MainWindow::receiveNewArgs(QStringList args)
|
||||
QString opmode = QString::fromStdString(opModeStr).toLower();
|
||||
//RsApplication::setOpMode(opModeStr.toLower()); // Do we need this??
|
||||
|
||||
RsInfo() << "Setting new operating mode to \"" << opmode.toStdString() << "\"";
|
||||
|
||||
if (opmode == "noturtle")
|
||||
opModeStatus->setCurrentIndex(static_cast<typename std::underlying_type<RsOpMode>::type>(RsOpMode::NOTURTLE) - 1);
|
||||
else if (opmode == "gaming")
|
||||
@ -1704,6 +1708,12 @@ void MainWindow::openRsCollection(const QString &filename)
|
||||
if (qinfo.exists()) {
|
||||
if (qinfo.absoluteFilePath().endsWith(RsCollection::ExtensionString)) {
|
||||
RsCollection collection;
|
||||
|
||||
if(!collection.load(filename))
|
||||
{
|
||||
RsErr() << "Could not open Rscollection file " << filename.toStdString();
|
||||
return;
|
||||
}
|
||||
collection.downloadFiles();
|
||||
//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;
|
||||
|
||||
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])
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
if(file.atEnd())
|
||||
if(file.atEnd())
|
||||
n-- ;
|
||||
else if(n < max_size)
|
||||
++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>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Use Local Server to get new arguments.</string>
|
||||
<string>Accept operating systems calls</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
|
@ -145,6 +145,7 @@ static bool notifyRunningInstance()
|
||||
// Connect to the Local Server of the main process to notify it
|
||||
// that a new process had been started
|
||||
|
||||
RsInfo() << "Trying to contact running instance through socket \"" << TARGET << "\"";
|
||||
QLocalSocket localSocket;
|
||||
localSocket.connectToServer(QString(TARGET));
|
||||
#ifdef DEBUG
|
||||
|
@ -240,6 +240,17 @@ RsApplication::RsApplication(const RsGUIConfigOptions& conf)
|
||||
}
|
||||
#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)
|
||||
qInstallMessageHandler(qt_msg_handler);
|
||||
#else
|
||||
@ -344,22 +355,27 @@ void RsApplication::slotConnectionEstablished()
|
||||
socket->close();
|
||||
delete socket;
|
||||
|
||||
QBuffer buffer;
|
||||
QDataStream in(&buffer);
|
||||
QStringList args;
|
||||
if(newArgs.error())
|
||||
{
|
||||
RsErr() << "Something when wrong in receiving arguments from operating system: " << newArgs.errorString().toStdString() ;
|
||||
return ;
|
||||
}
|
||||
QBuffer buffer;
|
||||
QDataStream in(&buffer);
|
||||
QStringList args;
|
||||
|
||||
newArgs.lock();
|
||||
buffer.setData((char*)newArgs.constData(), newArgs.size());
|
||||
buffer.open(QBuffer::ReadOnly);
|
||||
in >> args;
|
||||
newArgs.unlock();
|
||||
newArgs.detach();
|
||||
newArgs.lock();
|
||||
buffer.setData((char*)newArgs.constData(), newArgs.size());
|
||||
buffer.open(QBuffer::ReadOnly);
|
||||
in >> args;
|
||||
newArgs.unlock();
|
||||
newArgs.detach();
|
||||
|
||||
emit newArgsReceived(args);
|
||||
while (!args.empty())
|
||||
{
|
||||
emit newArgsReceived(args);
|
||||
while (!args.empty())
|
||||
{
|
||||
std::cerr << "RsApplication::slotConnectionEstablished args:" << QString(args.takeFirst()).toStdString() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString RsApplication::retroshareVersion(bool) { return RS_HUMAN_READABLE_VERSION; }
|
||||
|
Loading…
Reference in New Issue
Block a user