Skip to content

Commit cbef120

Browse files
committed
Merge branch 'master' of github.com:texstudio-org/texstudio
2 parents b5be8e4 + e1896ad commit cbef120

File tree

2 files changed

+91
-6
lines changed

2 files changed

+91
-6
lines changed

src/kpathseaParser.cpp

Lines changed: 88 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ MiktexPackageScanner::MiktexPackageScanner(QString mpmcmd, QString settingsDir,
8484
: PackageScanner(parent)
8585
{
8686
this->mpmCmd = mpmcmd;
87+
this->kpseWhichCmd = mpmcmd.replace("mpm.exe","kpsewhich.exe");
8788
this->settingsDir = settingsDir;
8889
}
8990

@@ -94,6 +95,13 @@ QString MiktexPackageScanner::mpm(const QString &arg)
9495
return execProgram.m_standardOutput;
9596
}
9697

98+
QString MiktexPackageScanner::kpsewhich(const QString &arg)
99+
{
100+
ExecProgram execProgram(kpseWhichCmd + " " + arg, "");
101+
execProgram.execAndWait();
102+
return execProgram.m_standardOutput;
103+
}
104+
97105
void MiktexPackageScanner::savePackageMap(const QHash<QString, QStringList> &map)
98106
{
99107
QFile f(ensureTrailingDirSeparator(settingsDir) + "miktexPackageNames.dat");
@@ -123,7 +131,57 @@ QHash<QString, QStringList> MiktexPackageScanner::loadPackageMap()
123131
result.insert(lst[0], lst[1].split(","));
124132
}
125133
}
126-
return result;
134+
return result;
135+
}
136+
137+
QHash<QString, QStringList> MiktexPackageScanner::loadMiktexPackageMap()
138+
{
139+
QHash<QString, QStringList> result;
140+
// try to load packages-manifest.ini
141+
QString txt=kpsewhich("-show-path=web2c");
142+
QStringList paths=txt.split(';');
143+
paths.pop_front(); // remove .
144+
QString fn;
145+
foreach(QString path,paths){
146+
path.replace("web2c//","miktex/config/package-manifests.ini");
147+
if(QFileInfo::exists(path.simplified())){
148+
fn=path.simplified();
149+
break;
150+
}
151+
}
152+
if(!fn.isEmpty()){
153+
QFile f(fn);
154+
if (f.open(QFile::ReadOnly | QFile::Text)) {
155+
QTextStream in(&f);
156+
QString line;
157+
QStringList lst;
158+
QString name;
159+
while (!in.atEnd()) {
160+
line = in.readLine();
161+
if(line.startsWith('[')){
162+
if(!name.isEmpty()){
163+
result.insert(name, lst);
164+
lst.clear();
165+
}
166+
// package name
167+
name=line.mid(1,line.size()-2);
168+
}
169+
if(line.startsWith("run[]=")){
170+
QString fn=line.mid(6);
171+
if(fn.contains('/')){
172+
int i=fn.lastIndexOf('/');
173+
fn=fn.mid(i+1);
174+
}
175+
if (fn.endsWith(".sty") || fn.endsWith(".cls")) {
176+
fn.chop(4);
177+
lst<<fn;
178+
}
179+
}
180+
181+
}
182+
}
183+
}
184+
return result;
127185
}
128186

129187
QStringList MiktexPackageScanner::stysForPackage(const QString &pck)
@@ -133,13 +191,33 @@ QStringList MiktexPackageScanner::stysForPackage(const QString &pck)
133191
bool inRunTimeFilesSection = false;
134192
foreach (const QString &l, lines) {
135193
if (!inRunTimeFilesSection) {
136-
if (l.startsWith("run-time files:"))
194+
if (l.startsWith("run-time files:")){
137195
inRunTimeFilesSection = true;
196+
// new output format has everything in the same line.
197+
QString rest=l.mid(16);
198+
// split at semicolon
199+
QStringList styles=rest.split(';');
200+
foreach(auto fn,styles){
201+
fn = QFileInfo(fn).fileName();
202+
if(fn.contains('/')){
203+
int i=fn.lastIndexOf('/');
204+
fn=fn.mid(i+1);
205+
}
206+
if (fn.endsWith(".sty") || fn.endsWith(".cls")) {
207+
fn.chop(4);
208+
result.append(fn);
209+
}
210+
}
211+
}
138212
continue;
139213
} else {
140214
QString fn = l.simplified();
141215
if (fn.endsWith(":")) break; // start of a new section
142216
fn = QFileInfo(fn).fileName();
217+
if(fn.contains('/')){
218+
int i=fn.lastIndexOf('/');
219+
fn=fn.mid(i+1);
220+
}
143221
if (fn.endsWith(".sty") || fn.endsWith(".cls")) {
144222
fn.chop(4);
145223
result.append(fn);
@@ -154,21 +232,26 @@ void MiktexPackageScanner::run()
154232
std::set<QString> results;
155233

156234
QHash<QString, QStringList> cachedStys = loadPackageMap();
235+
QHash<QString, QStringList> cachedMiktexStys = loadMiktexPackageMap();
157236

158237
QStringList lstOfPackages = mpm("--list").split("\n");
159238
foreach (QString pck, lstOfPackages) {
160239
if (stopped)
161240
return;
162241
QStringList parts = pck.simplified().split(" "); // output format of "mpm --list": installation status, number of files, size, database name
163242
if (parts.count() != 4) continue;
164-
if (parts[0] != "i") continue; // not installed
243+
if (parts[0] != "i" && parts[0].toLower() != "true") continue; // not installed
165244
pck = parts[3];
166245
QStringList stys;
167246
if (cachedStys.contains(pck)) {
168247
stys = cachedStys.value(pck);
169248
} else {
170-
stys = stysForPackage(pck);
171-
cachedStys.insert(pck, stys);
249+
if(cachedMiktexStys.contains(pck)){
250+
stys = cachedMiktexStys.value(pck);
251+
}else{
252+
stys = stysForPackage(pck);
253+
cachedStys.insert(pck, stys);
254+
}
172255
}
173256
foreach (const QString &sty, stys) {
174257
results.insert(sty);

src/kpathseaParser.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,14 @@ class MiktexPackageScanner : public PackageScanner
5454
protected:
5555
void run();
5656
QString mpm(const QString &arg);
57+
QString kpsewhich(const QString &arg);
5758
void savePackageMap(const QHash<QString, QStringList> &map);
5859
QHash<QString, QStringList> loadPackageMap();
60+
QHash<QString, QStringList> loadMiktexPackageMap();
5961
QStringList stysForPackage(const QString &pck);
6062

6163
private:
62-
QString mpmCmd;
64+
QString mpmCmd,kpseWhichCmd;
6365
QString settingsDir;
6466
};
6567

0 commit comments

Comments
 (0)