- fix: path in macros should use system's path separator

This commit is contained in:
Roy Qu 2021-12-09 08:10:14 +08:00
parent 64ea9aad7e
commit 319c26902c
5 changed files with 41 additions and 33 deletions

View File

@ -219,7 +219,7 @@ void CompilerManager::run(const QString &filename, const QString &arguments, con
if (consoleFlag!=0) {
QString newArguments = QString(" %1 \"%2\" %3")
.arg(consoleFlag)
.arg(toLocalPath(filename)).arg(arguments);
.arg(localizePath(filename)).arg(arguments);
execRunner = new ExecutableRunner(includeTrailingPathDelimiter(pSettings->dirs().app())+"ConsolePauser.exe",newArguments,workDir);
} else {
execRunner = new ExecutableRunner(filename,arguments,workDir);

View File

@ -1802,18 +1802,20 @@ void MainWindow::updateTools()
foreach (const PToolItem& item, mToolsManager->tools()) {
QAction* action = new QAction(item->title,ui->menuTools);
connect(action, &QAction::triggered,
[item,this] (){
QString params = parseMacros(item->parameters);
params.replace("/",QDir::separator());
QByteArray newContent = runAndGetOutput(
[item] (){
if (item->pauseAfterExit
&& programHasConsole(parseMacros(item->program))) {
executeFile(
includeTrailingPathDelimiter(pSettings->dirs().app())+"ConsolePauser.exe",
" 0 \""+parseMacros(item->program)+"\" "+parseMacros(item->parameters),
parseMacros(item->workingDirectory));
} else {
executeFile(
parseMacros(item->program),
parseMacros(item->workingDirectory),
QProcess::splitCommand(params),
QByteArray(),
true
);
qDebug()<<"running"<<item->program;
ui->txtCompilerOutput->appendPlainText(QString::fromLocal8Bit(newContent));
parseMacros(item->parameters),
parseMacros(item->workingDirectory));
}
});
ui->menuTools->addAction(action);
}

View File

@ -293,13 +293,6 @@ bool programHasConsole(const QString &filename)
return result;
}
QString toLocalPath(const QString &filename)
{
QString newPath {filename};
newPath.replace("/",QDir::separator());
return newPath;
}
QStringList textToLines(const QString &text)
{
QTextStream stream(&((QString&)text),QIODevice::ReadOnly);
@ -767,10 +760,10 @@ QString parseMacros(const QString &s)
QString result = s;
Editor *e = pMainWindow->editorList()->getEditor();
result.replace("<DEFAULT>", QDir::currentPath());
result.replace("<DEVCPP>", pSettings->dirs().executable());
result.replace("<DEFAULT>", localizePath(QDir::currentPath()));
result.replace("<DEVCPP>", localizePath(pSettings->dirs().executable()));
result.replace("<DEVCPPVERSION>", DEVCPP_VERSION);
result.replace("<EXECPATH>", pSettings->dirs().app());
result.replace("<EXECPATH>", localizePath(pSettings->dirs().app()));
QDate today = QDate::currentDate();
QDateTime now = QDateTime::currentDateTime();
@ -781,30 +774,34 @@ QString parseMacros(const QString &s)
if (compilerSet) {
// Only provide the first cpp include dir
if (compilerSet->defaultCppIncludeDirs().count()>0)
result.replace("<INCLUDE>", compilerSet->defaultCppIncludeDirs().front());
result.replace("<INCLUDE>", localizePath(compilerSet->defaultCppIncludeDirs().front()));
else
result.replace("<INCLUDE>","");
// Only provide the first lib dir
if (compilerSet->defaultLibDirs().count()>0)
result.replace("<LIB>", compilerSet->defaultCppIncludeDirs().front());
result.replace("<LIB>", localizePath(compilerSet->defaultCppIncludeDirs().front()));
else
result.replace("<LIB>","");
}
// Project-dependent macros
if (pMainWindow->project()) {
result.replace("<EXENAME>", pMainWindow->project()->executable());
result.replace("<EXENAME>", extractFileName(pMainWindow->project()->executable()));
result.replace("<EXEFILE>", localizePath(pMainWindow->project()->executable()));
result.replace("<PROJECTNAME>", pMainWindow->project()->name());
result.replace("<PROJECTFILE>", pMainWindow->project()->filename());
result.replace("<PROJECTPATH>", pMainWindow->project()->directory());
result.replace("<PROJECTFILE>", localizePath(pMainWindow->project()->filename()));
result.replace("<PROJECTFILENAME>", extractFileName(pMainWindow->project()->filename()));
result.replace("<PROJECTPATH>", localizePath(pMainWindow->project()->directory()));
// result.replace("<SOURCESPCLIST>', MainForm.Project.ListUnitStr(' '));
// result.replace("<SOURCESPCLIST>","");
} else if (e!=nullptr) { // Non-project editor macros
result.replace("<EXENAME>", changeFileExt(e->filename(),EXECUTABLE_EXT));
result.replace("<EXENAME>", extractFileName(changeFileExt(e->filename(),EXECUTABLE_EXT)));
result.replace("<EXEFILE>", localizePath(changeFileExt(e->filename(),EXECUTABLE_EXT)));
result.replace("<PROJECTNAME>", extractFileName(e->filename()));
result.replace("<PROJECTFILE>",e->filename());
result.replace("<PROJECTPATH>", extractFileDir(e->filename()));
result.replace("<PROJECTFILE>", localizePath(e->filename()));
result.replace("<PROJECTFILENAME>", extractFileName(e->filename()));
result.replace("<PROJECTPATH>", localizePath(extractFileDir(e->filename())));
// result.replace("<SOURCESPCLIST>", ""); // clear unchanged macros
} else {
result.replace("<EXENAME>", "");
@ -817,8 +814,8 @@ QString parseMacros(const QString &s)
// Editor macros
if (e!=nullptr) {
result.replace("<SOURCENAME>", extractFileName(e->filename()));
result.replace("<SOURCEFILE>", e->filename());
result.replace("<SOURCEPATH>", extractFileDir(e->filename()));
result.replace("<SOURCEFILE>", localizePath(e->filename()));
result.replace("<SOURCEPATH>", localizePath(extractFileDir(e->filename())));
result.replace("<WORDXY>", e->wordAtCursor());
} else {
result.replace("<SOURCENAME>", "");
@ -928,3 +925,10 @@ QList<QByteArray> splitByteArrayToLines(const QByteArray &content)
}
return lines;
}
QString localizePath(const QString &path)
{
QString result = path;
result.replace("/",QDir::separator());
return result;
}

View File

@ -138,7 +138,6 @@ QString genMakePath2(const QString& fileName);
QString getCompiledExecutableName(const QString& filename);
void splitStringArguments(const QString& arguments, QStringList& argumentList);
bool programHasConsole(const QString& filename);
QString toLocalPath(const QString& filename);
using LineProcessFunc = std::function<void(const QString&)>;
QStringList readStreamToLines(QTextStream* stream);
@ -178,6 +177,7 @@ bool findComplement(const QString& s,
int increment);
void logToFile(const QString& s, const QString& filename, bool append=true);
QString localizePath(const QString& path);
QString extractFileName(const QString& fileName);
QString extractFileDir(const QString& fileName);
QString extractFilePath(const QString& filePath);

View File

@ -11,12 +11,14 @@ MacroInfoModel::MacroInfoModel(QObject *parent) : QAbstractListModel(parent)
addMacroInfo("<INCLUDE>", tr("The first include directory of the working compiler set."));
addMacroInfo("<LIB>", tr("The first lib directory of the working compiler set."));
addMacroInfo("<EXENAME>", tr("The compiled filename"));
addMacroInfo("<EXEFILE>", tr("Full path to the compiled file"));
addMacroInfo("<SOURCENAME>", tr("Filename of the current source file"));
addMacroInfo("<SOURCEFILE>", tr("Full path to the current source file"));
addMacroInfo("<SOURCEPATH>", tr("Path to the current source file's parent folder"));
addMacroInfo("<WORDXY>", tr("Word at the cursor in the active editor"));
addMacroInfo("<PROJECTNAME>", tr("Name of the current project"));
addMacroInfo("<PROJECTFILE>", tr("Full path to the current project file"));
addMacroInfo("<PROJECTFILENAME>", tr("Name of the current project file"));
addMacroInfo("<PROJECTPATH>", tr("Path to the current project's folder"));
}