MiKTeX 23.10-next
A scalable TeX distribution
Loading...
Searching...
No Matches
Session.h
1/* miktex/Core/Session.h: MiKTeX session
2
3 Copyright (C) 1996-2022 Christian Schenk
4
5 This file is part of the MiKTeX Core Library.
6
7 The MiKTeX Core Library is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2, or
10 (at your option) any later version.
11
12 The MiKTeX Core Library is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
14 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with the MiKTeX Core Library; if not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
21
22#pragma once
23
24#if !defined(B4CE13E8A2514CC8B46D9F6D49EEDC60)
25#define B4CE13E8A2514CC8B46D9F6D49EEDC60
26
27#include <miktex/Core/config.h>
28
29#if defined(MIKTEX_WINDOWS)
30# include <Windows.h>
31#endif
32
33#include <cstddef>
34
35#include <chrono>
36#include <memory>
37#include <ostream>
38#include <string>
39#include <vector>
40
41#include <miktex/Configuration/ConfigurationProvider>
42#include <miktex/Configuration/HasNamedValues>
43#include <miktex/Configuration/TriState>
44#include <miktex/Core/Text>
45#include <miktex/Util/OptionSet>
46#include <miktex/Util/PathName>
47#include <miktex/Trace/TraceCallback>
48#include <miktex/Util/DateUtil>
49
50#include "Exceptions.h"
51#include "File.h"
52#include "FileType.h"
53#include "Process.h"
54#include "RootDirectoryInfo.h"
55#include "VersionNumber.h"
56
59#define MIKTEX_SESSION() ([]() \
60{ \
61 auto session = MiKTeX::Core::Session::TryGet(); \
62 if (session == nullptr) \
63 { \
64 MIKTEX_UNEXPECTED(); \
65 } \
66 return session; \
67} \
68())
69
72MIKTEX_CORE_BEGIN_NAMESPACE;
73
75constexpr unsigned INVALID_ROOT_INDEX = static_cast<unsigned>(-1);
76
79{
80 None,
82 Regular,
84 Direct,
87};
88
89inline std::ostream& operator<<(std::ostream& os, const MiKTeXConfiguration& miktexConfiguration)
90{
91 switch (miktexConfiguration)
92 {
93 case MiKTeXConfiguration::None: os << "None"; break;
94 case MiKTeXConfiguration::Regular: os << "Regular"; break;
95 case MiKTeXConfiguration::Direct: os << "Direct"; break;
96 case MiKTeXConfiguration::Portable: os << "Portable"; break;
97 }
98 return os;
99}
100
103{
104 None,
106 User,
108 Common
109};
110
111inline std::ostream& operator<<(std::ostream& os, const ConfigurationScope& scope)
112{
113 switch (scope)
114 {
115 case ConfigurationScope::None: os << "None"; break;
116 case ConfigurationScope::User: os << "User"; break;
117 case ConfigurationScope::Common: os << "Common"; break;
118 }
119 return os;
120}
121
124{
127
130
133
135 std::string userRoots;
136
138 std::string otherUserRoots;
139
142
145
148
150 std::string commonRoots;
151
153 std::string otherCommonRoots;
154
156 MiKTeXConfiguration config = MiKTeXConfiguration::None;
157};
158
159inline std::ostream& operator<<(std::ostream& os, const StartupConfig& startupConfig)
160{
161 if (!startupConfig.userConfigRoot.Empty())
162 {
163 os << "UserConfig=" << startupConfig.userConfigRoot << ",";
164 }
165 if (!startupConfig.userDataRoot.Empty())
166 {
167 os << "UserData=" << startupConfig.userDataRoot << ",";
168 }
169 if (!startupConfig.userInstallRoot.Empty())
170 {
171 os << "UserInstall=" << startupConfig.userInstallRoot << ",";
172 }
173 if (!startupConfig.userRoots.empty())
174 {
175 os << "UserRoots=" << startupConfig.userRoots << ",";
176 }
177 if (!startupConfig.otherUserRoots.empty())
178 {
179 os << "OtherUserRoots=" << startupConfig.otherUserRoots << ",";
180 }
181 if (!startupConfig.commonConfigRoot.Empty())
182 {
183 os << "CommonConfig=" << startupConfig.commonConfigRoot << ",";
184 }
185 if (!startupConfig.commonDataRoot.Empty())
186 {
187 os << "CommonData=" << startupConfig.commonDataRoot << ",";
188 }
189 if (!startupConfig.commonInstallRoot.Empty())
190 {
191 os << "CommonInstall=" << startupConfig.commonInstallRoot << ",";
192 }
193 if (!startupConfig.commonRoots.empty())
194 {
195 os << "CommonRoots=" << startupConfig.commonRoots << ",";
196 }
197 if (!startupConfig.otherCommonRoots.empty())
198 {
199 os << "OtherCommonRoots=" << startupConfig.otherCommonRoots << ",";
200 }
201 os << "MiKTeXConfiguration=" << startupConfig.config;
202 return os;
203}
204
206{
207 std::time_t setupDate = MiKTeX::Util::DateUtil::UNDEFINED_TIME_T_VALUE;
208 VersionNumber setupVersion;
209 bool isNew = false;
210};
211
214{
215 static MIKTEXCORECEEAPI(PaperSizeInfo) Parse(const std::string &spec);
216
218 std::string name;
219
220 std::string dvipsName;
221
223 int width;
224
227};
228
231{
232 std::string mnemonic;
233 std::string description;
234 int horizontalResolution;
235 int verticalResolution;
236};
237
240{
242 FileType fileType = FileType::None;
244 std::string fileTypeString;
246 std::vector<std::string> fileNameExtensions;
248 std::vector<std::string> alternateExtensions;
250 std::vector<std::string> searchPath;
252 std::vector<std::string> envVarNames;
253};
254
257{
258 std::string fileName;
259 std::string packageName;
260 FileAccess access = FileAccess::None;
261};
262
265{
266 enum { Developer = 1, Contributor = 2, Sponsor = 4, KnownUser = 8 };
267 enum { Individual = 100 };
268 std::string userid;
269 std::string name;
270 std::string organization;
271 std::string email;
272 int role = 0;
273 int level = 0;
274 std::time_t expirationDate = MiKTeX::Util::DateUtil::UNDEFINED_TIME_T_VALUE;
275 bool IsMember () const
276 {
277 return level >= Individual && (!MiKTeX::Util::DateUtil::IsDefined(expirationDate) || expirationDate >= std::time(nullptr));
278 }
279 bool IsDeveloper () const { return IsMember() && (role & Developer) != 0; }
280 bool IsContributor () const { return IsMember() && (role & Contributor) != 0; }
281 bool IsSponsor () const { return IsMember() && (role & Sponsor) != 0; }
282 bool IsKnownUser () const { return IsMember() && (role & KnownUser) != 0; }
283};
284
287{
289 std::string key;
291 std::string name;
293 std::string description;
295 std::string compiler;
297 std::string inputFile;
299 std::string outputFile;
301 std::string preloaded;
303 bool exclude = false;
305 bool noExecutable = false;
307 bool custom = false;
309 std::vector<std::string> arguments;
310};
311
314{
315 std::string key;
316 std::string synonyms;
317 std::string loader;
318 std::string patterns;
319 std::string hyphenation;
320 std::string luaspecial;
321 int lefthyphenmin = -1;
322 int righthyphenmin = -1;
323 bool exclude = false;
324 bool custom = false;
325};
326
328enum class ExpandOption
329{
331 Values,
333 Braces,
336};
337
338typedef MiKTeX::Util::OptionSet<ExpandOption> ExpandOptionSet;
339
342{
343#if defined(MIKTEX_WINDOWS)
346#endif
348 Temporary,
350 Review
351};
352
353typedef MiKTeX::Util::OptionSet<RegisterRootDirectoriesOption> RegisterRootDirectoriesOptionSet;
354
357{
359 Forbidden,
363 Query,
366};
367
369class MIKTEXNOVTABLE IFindFileCallback
370{
371public:
377 virtual bool MIKTEXTHISCALL InstallPackage(const std::string& packageId, const MiKTeX::Util::PathName& trigger, MiKTeX::Util::PathName& installRoot) = 0;
378
383 virtual bool MIKTEXTHISCALL TryCreateFile(const MiKTeX::Util::PathName& fileName, FileType fileType) = 0;
384};
385
387 bool all = false;
388 IFindFileCallback* callback = nullptr;
389 FileType fileType = FileType::None;
390 bool create = false;
391 bool renew = false;
392 bool searchFileSystem = false;
393 std::string searchPath;
394};
395
397 std::vector<MiKTeX::Util::PathName> pathNames;
398};
399
401class MIKTEXNOVTABLE Session :
403{
404public:
406 enum class FindFileOption
407 {
409 Create,
411 Renew,
413 All,
415 SearchFileSystem
416 };
417
418 typedef MiKTeX::Util::OptionSet<FindFileOption> FindFileOptionSet;
419
421 enum class InitOption
422 {
424 SettingUp,
426 NoFixPath,
428 AdminMode,
429 };
430
433
436 {
437 public:
438 InitInfo() = default;
439 InitInfo(const InitInfo& other) = default;
440 InitInfo& operator=(const InitInfo& other) = default;
441 InitInfo(InitInfo&& other) = default;
442 InitInfo& operator=(InitInfo&& other) = default;
443 ~InitInfo() = default;
444
447 InitInfo(const std::string& programInvocationName) :
448 programInvocationName(programInvocationName)
449 {
450 }
451
455 InitInfo(const std::string& programInvocationName, InitOptionSet options) :
456 options(options),
457 programInvocationName(programInvocationName)
458 {
459 }
460
464 {
465 this->options = options;
466 }
467
471 {
472 return options;
473 }
474
478 {
479 this->options += option;
480 }
481
484 void SetProgramInvocationName(const std::string& programInvocationName)
485 {
486 this->programInvocationName = programInvocationName;
487 }
488
491 std::string GetProgramInvocationName() const
492 {
493 return programInvocationName;
494 }
495
498 void SetTheNameOfTheGame(const std::string& theNameOfTheGame)
499 {
500 this->theNameOfTheGame = theNameOfTheGame;
501 }
502
505 std::string GetTheNameOfTheGame() const
506 {
507 return theNameOfTheGame;
508 }
509
512 void SetStartupConfig(const StartupConfig& startupConfig)
513 {
514 this->startupConfig = startupConfig;
515 }
516
520 {
521 return startupConfig;
522 }
523
526 void SetTraceFlags(const std::string& traceFlags)
527 {
528 this->traceFlags = traceFlags;
529 }
530
533 std::string GetTraceFlags() const
534 {
535 return traceFlags;
536 }
537
541 {
542 traceCallback = callback;
543 }
544
548 {
549 return traceCallback;
550 }
551
552 private:
553 InitOptionSet options;
554 std::string programInvocationName;
555 std::string theNameOfTheGame;
556 StartupConfig startupConfig;
557 std::string traceFlags;
558 MiKTeX::Trace::TraceCallback* traceCallback = nullptr;
559 };
560
563 {
564 const FILE* file = nullptr;
565 std::string fileName;
566 FileMode mode = FileMode::Open;
567 FileAccess access = FileAccess::None;
568 };
569
572 static MIKTEXCORECEEAPI(std::shared_ptr<Session>) TryGet();
573
577 static MIKTEXCORECEEAPI(std::shared_ptr<Session>) Create(const InitInfo& initInfo);
578
579 virtual MIKTEXTHISCALL ~Session() noexcept = 0;
580
582 virtual void MIKTEXTHISCALL Close() = 0;
583
585 virtual void MIKTEXTHISCALL Reset() = 0;
586
589 virtual void MIKTEXTHISCALL PushAppName(const std::string& name) = 0;
590
593 virtual void MIKTEXTHISCALL PushBackAppName(const std::string& name) = 0;
594
598 virtual void MIKTEXTHISCALL AddInputDirectory(const MiKTeX::Util::PathName& path, bool atEnd) = 0;
599
602 virtual std::vector<RootDirectoryInfo> GetRootDirectories() = 0;
603
606 virtual unsigned MIKTEXTHISCALL GetNumberOfTEXMFRoots() = 0;
607
611 virtual MiKTeX::Util::PathName MIKTEXTHISCALL GetRootDirectoryPath(unsigned r) = 0;
612
616 virtual bool MIKTEXTHISCALL IsCommonRootDirectory(unsigned r) = 0;
617
621 virtual bool MIKTEXTHISCALL IsOtherRootDirectory(unsigned r) = 0;
622
625 virtual MiKTeX::Util::PathName MIKTEXTHISCALL GetMpmRootPath() = 0;
626
629 virtual MiKTeX::Util::PathName MIKTEXTHISCALL GetMpmDatabasePathName() = 0;
630
634 virtual unsigned MIKTEXTHISCALL TryDeriveTEXMFRoot(const MiKTeX::Util::PathName& path) = 0;
635
639 virtual unsigned MIKTEXTHISCALL DeriveTEXMFRoot(const MiKTeX::Util::PathName& path) = 0;
640
645 virtual bool MIKTEXTHISCALL FindFilenameDatabase(unsigned r, MiKTeX::Util::PathName& path) = 0;
646
650 virtual MiKTeX::Util::PathName MIKTEXTHISCALL GetFilenameDatabasePathName(unsigned r) = 0;
651
655 virtual bool MIKTEXTHISCALL UnloadFilenameDatabase() = 0;
656
661 virtual bool MIKTEXTHISCALL UnloadFilenameDatabase(std::chrono::duration<double> minIdleTime) = 0;
662
668 virtual unsigned MIKTEXTHISCALL SplitTEXMFPath(const MiKTeX::Util::PathName& path, MiKTeX::Util::PathName& root, MiKTeX::Util::PathName& relative) = 0;
669
673 virtual void MIKTEXTHISCALL RegisterRootDirectories(const StartupConfig& startupConfig, RegisterRootDirectoriesOptionSet options) = 0;
674
678 virtual void MIKTEXTHISCALL RegisterRootDirectory(const MiKTeX::Util::PathName& path, bool other) = 0;
679
683 virtual void MIKTEXTHISCALL UnregisterRootDirectory(const MiKTeX::Util::PathName& path, bool other) = 0;
684
687 virtual void MIKTEXTHISCALL MoveRootDirectoryUp(unsigned r) = 0;
688
691 virtual void MIKTEXTHISCALL MoveRootDirectoryDown(unsigned r) = 0;
692
695 virtual bool MIKTEXTHISCALL IsMiKTeXDirect() = 0;
696
699 virtual bool MIKTEXTHISCALL IsMiKTeXPortable() = 0;
700
705 virtual bool MIKTEXTHISCALL GetMETAFONTMode(unsigned idx, MIKTEXMFMODE& mode) = 0;
706
711 virtual bool MIKTEXTHISCALL DetermineMETAFONTMode(unsigned dpi, MIKTEXMFMODE& Mode) = 0;
712
715 virtual std::string MIKTEXTHISCALL GetEngineName() = 0;
716
723 virtual FILE* MIKTEXTHISCALL OpenFile(const MiKTeX::Util::PathName& path, FileMode mode, FileAccess access, bool isTextFile) = 0;
724
732 virtual FILE* MIKTEXTHISCALL TryOpenFile(const MiKTeX::Util::PathName& path, FileMode mode, FileAccess access, bool isTextFile) = 0;
733
738 virtual std::pair<bool, OpenFileInfo> MIKTEXTHISCALL TryGetOpenFileInfo(FILE* file) = 0;
739
742 virtual void MIKTEXTHISCALL CloseFile(FILE* file, int& exitCode) = 0;
743
746 virtual void MIKTEXTHISCALL CloseFile(FILE* file) = 0;
747
751 virtual bool MIKTEXTHISCALL IsOutputFile(const FILE* file) = 0;
752
753#if defined(MIKTEX_WINDOWS)
757 virtual bool MIKTEXTHISCALL IsFileAlreadyOpen(const MiKTeX::Util::PathName& fileName) = 0;
758#endif
759
762 virtual void MIKTEXTHISCALL ScheduleSystemCommand(const std::string& commandLine) = 0;
763
764#if defined(MIKTEX_WINDOWS)
767 virtual void MIKTEXTHISCALL ScheduleFileRemoval(const MiKTeX::Util::PathName& path) = 0;
768#endif
769
772 virtual bool MIKTEXTHISCALL StartFileInfoRecorder() = 0;
773
777 virtual bool MIKTEXTHISCALL StartFileInfoRecorder(bool recordPackageNames) = 0;
778
781 virtual void MIKTEXTHISCALL SetRecorderPath(const MiKTeX::Util::PathName& path) = 0;
782
786 virtual void MIKTEXTHISCALL RecordFileInfo(const MiKTeX::Util::PathName& path, FileAccess access) = 0;
787
790 virtual std::vector<FileInfoRecord> MIKTEXTHISCALL GetFileInfoRecords() = 0;
791
795 virtual FileType MIKTEXTHISCALL DeriveFileType(const MiKTeX::Util::PathName& fileName) = 0;
796
801 virtual LocateResult MIKTEXTHISCALL Locate(const std::string& fileName, const LocateOptions& options) = 0;
802
809 virtual bool MIKTEXTHISCALL FindFile(const std::string& fileName, const std::string& searchPath, FindFileOptionSet options, std::vector<MiKTeX::Util::PathName>& result) = 0;
810
816 virtual bool MIKTEXTHISCALL FindFile(const std::string& fileName, const std::string& searchPath, std::vector<MiKTeX::Util::PathName>& result) = 0;
817
824 virtual bool MIKTEXTHISCALL FindFile(const std::string& fileName, const std::string& searchPath, FindFileOptionSet options, MiKTeX::Util::PathName& result) = 0;
825
831 virtual bool MIKTEXTHISCALL FindFile(const std::string& fileName, const std::string& searchPath, MiKTeX::Util::PathName& result) = 0;
832
839 virtual bool MIKTEXTHISCALL FindFile(const std::string& fileName, FileType fileType, FindFileOptionSet options, std::vector<MiKTeX::Util::PathName>& result) = 0;
840
846 virtual bool MIKTEXTHISCALL FindFile(const std::string& fileName, FileType fileType, std::vector<MiKTeX::Util::PathName>& result) = 0;
847
854 virtual bool MIKTEXTHISCALL FindFile(const std::string& fileName, FileType fileType, FindFileOptionSet options, MiKTeX::Util::PathName& result) = 0;
855
861 virtual bool MIKTEXTHISCALL FindFile(const std::string& fileName, FileType fileType, MiKTeX::Util::PathName& result) = 0;
862
869 virtual bool MIKTEXTHISCALL FindPkFile(const std::string& fontName, const std::string& mfMode, int dpi, MiKTeX::Util::PathName& result) = 0;
870
876 virtual bool MIKTEXTHISCALL FindTfmFile(const std::string& fontName, MiKTeX::Util::PathName& result, bool create) = 0;
877
880 virtual void MIKTEXTHISCALL SetFindFileCallback(IFindFileCallback* callback) = 0;
881
889 virtual void MIKTEXTHISCALL SplitFontPath(const MiKTeX::Util::PathName& fontPath, std::string* fontType, std::string* supplier, std::string* typeface, std::string* fontName, std::string* pointSize) = 0;
890
897 virtual bool MIKTEXTHISCALL GetFontInfo(const std::string& fontName, std::string& supplier, std::string& typeface, double* genSize) = 0;
898
902 virtual MiKTeX::Util::PathName MIKTEXTHISCALL GetGhostscript(unsigned long* versionNumber) = 0;
903
907 virtual std::string MIKTEXTHISCALL GetExpandedSearchPath(FileType fileType) = 0;
908
914 virtual bool MIKTEXTHISCALL ConvertToBitmapFile(const MiKTeX::Util::PathName& sourceFileName, MiKTeX::Util::PathName& destFileName, IRunProcessCallback* callback) = 0;
915
919 virtual bool MIKTEXTHISCALL EnableFontMaker(bool enable) = 0;
920
923 virtual bool MIKTEXTHISCALL GetMakeFontsFlag() = 0;
924
933 virtual std::vector<std::string> MIKTEXTHISCALL MakeMakePkCommandLine(const std::string& fontName, int dpi, int baseDpi, const std::string& mfMode, MiKTeX::Util::PathName& fileName, MiKTeX::Configuration::TriState enableInstaller) = 0;
934
935#if defined(MIKTEX_WINDOWS)
940 virtual int MIKTEXTHISCALL RunBatch(int argc, const char** argv) = 0;
941#endif
942
947 virtual int MIKTEXTHISCALL RunExe(int argc, const char** argv) = 0;
948
953 virtual int MIKTEXTHISCALL RunGhostscript(int argc, const char** argv) = 0;
954
955#if !defined(MIKTEX_WINDOWS)
960 virtual int MIKTEXTHISCALL RunSh(int argc, const char** argv) = 0;
961#endif
962
967 virtual int MIKTEXTHISCALL RunPerl(int argc, const char** argv) = 0;
968
973 virtual int MIKTEXTHISCALL RunPython(int argc, const char** argv) = 0;
974
979 virtual int MIKTEXTHISCALL RunJava(int argc, const char** argv) = 0;
980
981#if defined(MIKTEX_WINDOWS)
986 virtual bool MIKTEXTHISCALL ShowManualPageAndWait(HWND hWnd, unsigned long topic) = 0;
987#endif
988
991 virtual std::vector<FileTypeInfo> MIKTEXTHISCALL GetFileTypes() = 0;
992
995 virtual std::vector<FormatInfo> MIKTEXTHISCALL GetFormats() = 0;
996
1000 virtual FormatInfo MIKTEXTHISCALL GetFormatInfo(const std::string& key) = 0;
1001
1006 virtual bool MIKTEXTHISCALL TryGetFormatInfo(const std::string& key, FormatInfo& formatInfo) = 0;
1007
1010 virtual void MIKTEXTHISCALL DeleteFormatInfo(const std::string& key) = 0;
1011
1014 virtual void MIKTEXTHISCALL SetFormatInfo(const FormatInfo& formatInfo) = 0;
1015
1018 virtual std::vector<LanguageInfo> MIKTEXTHISCALL GetLanguages() = 0;
1019
1023 virtual MiKTeX::Util::PathName MIKTEXTHISCALL GetMyProgramFile(bool canonicalized) = 0;
1024
1028 virtual MiKTeX::Util::PathName MIKTEXTHISCALL GetMyLocation(bool canonicalized) = 0;
1029
1033 virtual MiKTeX::Util::PathName MIKTEXTHISCALL GetMyPrefix(bool canonicalized) = 0;
1034
1037 virtual bool MIKTEXTHISCALL RunningAsAdministrator() = 0;
1038
1042 virtual void MIKTEXTHISCALL SetAdminMode(bool adminMode, bool force = false) = 0;
1043
1046 virtual bool MIKTEXTHISCALL IsAdminMode() = 0;
1047
1050 virtual bool MIKTEXTHISCALL IsSharedSetup() = 0;
1051
1054 virtual SetupConfig MIKTEXTHISCALL GetSetupConfig() = 0;
1055
1060 virtual bool MIKTEXTHISCALL GetPaperSizeInfo(int idx, PaperSizeInfo& paperSize) = 0;
1061
1065 virtual PaperSizeInfo MIKTEXTHISCALL GetPaperSizeInfo(const std::string& dvipsName) = 0;
1066
1069 virtual void MIKTEXTHISCALL SetDefaultPaperSize(const std::string& dvipsName) = 0;
1070
1074 virtual bool MIKTEXTHISCALL TryCreateFromTemplate(const MiKTeX::Util::PathName& path) = 0;
1075
1078 virtual bool MIKTEXTHISCALL IsUserAnAdministrator() = 0;
1079
1084 virtual void MIKTEXTHISCALL ConfigureFile(const MiKTeX::Util::PathName& pathIn, const MiKTeX::Util::PathName& pathOut, MiKTeX::Configuration::HasNamedValues* callback = nullptr) = 0;
1085
1089 virtual void MIKTEXTHISCALL ConfigureFile(const MiKTeX::Util::PathName& pathRel, MiKTeX::Configuration::HasNamedValues* callback = nullptr) = 0;
1090
1093 virtual void MIKTEXTHISCALL SetTheNameOfTheGame(const std::string& name) = 0;
1094
1097 virtual std::vector<std::string> MIKTEXTHISCALL GetFontDirectories() = 0;
1098
1102 virtual FileTypeInfo MIKTEXTHISCALL GetFileTypeInfo(FileType fileType) = 0;
1103
1107 virtual std::string Expand(const std::string& toBeExpanded) = 0;
1108
1113 virtual std::string Expand(const std::string& toBeExpanded, MiKTeX::Configuration::HasNamedValues* callback) = 0;
1114
1120 virtual std::string Expand(const std::string& toBeExpanded, ExpandOptionSet options, MiKTeX::Configuration::HasNamedValues* callback) = 0;
1121
1124 virtual void MIKTEXTHISCALL SetLanguageInfo(const LanguageInfo& languageInfo) = 0;
1125
1126#if HAVE_MIKTEX_USER_INFO
1130 virtual MiKTeXUserInfo RegisterMiKTeXUser(const MiKTeXUserInfo& info) = 0;
1131#endif
1132
1133#if HAVE_MIKTEX_USER_INFO
1137 virtual bool TryGetMiKTeXUserInfo(MiKTeXUserInfo& info) = 0;
1138#endif
1139
1143
1146 virtual std::vector<std::string> GetAllowedShellCommands() = 0;
1147
1150 {
1152 ProbablySafe,
1154 MaybeSafe,
1156 NotSafe,
1158 SyntaxError
1159 };
1160
1167 virtual std::tuple<ExamineCommandLineResult, std::string, std::string> ExamineCommandLine(const std::string& commandLine) = 0;
1168
1174 static MIKTEXCOREEXPORT MIKTEXNORETURN void MIKTEXCEECALL FatalCrtError(const std::string& functionName, int errorCode, const MiKTeXException::KVMAP& info, const SourceLocation& sourceLocation);
1175
1183 static MIKTEXCOREEXPORT MIKTEXNORETURN void MIKTEXCEECALL FatalMiKTeXError(const std::string& message, const std::string& description, const std::string& remedy, const std::string& tag, const MiKTeXException::KVMAP& info, const SourceLocation& sourceLocation);
1184
1185#if defined(MIKTEX_WINDOWS)
1194 static MIKTEXCOREEXPORT MIKTEXNORETURN void MIKTEXCEECALL FatalWindowsError(const std::string& functionName, unsigned long errorCode, const std::string& description, const std::string& remedy, const std::string& tag, const MiKTeXException::KVMAP& info, const SourceLocation& sourceLocation);
1195#endif
1196};
1197
1198MIKTEX_CORE_END_NAMESPACE;
1199
1200#define MIKTEX_FATAL_ERROR(message) \
1201 MiKTeX::Core::Session::FatalMiKTeXError(message, "", "", "", MiKTeX::Core::MiKTeXException::KVMAP(), MIKTEX_SOURCE_LOCATION())
1202
1203#define MIKTEX_FATAL_ERROR_2(message, ...) \
1204 MiKTeX::Core::Session::FatalMiKTeXError(message, "", "", "", MiKTeX::Core::MiKTeXException::KVMAP(__VA_ARGS__), MIKTEX_SOURCE_LOCATION())
1205
1206#define MIKTEX_FATAL_ERROR_3(message, description, ...) \
1207 MiKTeX::Core::Session::FatalMiKTeXError(message, description, "", "", MiKTeX::Core::MiKTeXException::KVMAP(__VA_ARGS__), MIKTEX_SOURCE_LOCATION())
1208
1209#define MIKTEX_FATAL_ERROR_4(message, description, remedy, ...) \
1210 MiKTeX::Core::Session::FatalMiKTeXError(message, description, remedy, "", MiKTeX::Core::MiKTeXException::KVMAP(__VA_ARGS__), MIKTEX_SOURCE_LOCATION())
1211
1212#define MIKTEX_FATAL_ERROR_5(message, description, remedy, tag, ...) \
1213 MiKTeX::Core::Session::FatalMiKTeXError(message, description, remedy, tag, MiKTeX::Core::MiKTeXException::KVMAP(__VA_ARGS__), MIKTEX_SOURCE_LOCATION())
1214
1215#define MIKTEX_STRINGIFY_(x) #x
1216#define MIKTEX_STRINGIFY(x) MIKTEX_STRINGIFY_(x)
1217
1218#define MIKTEX_INTERNAL_ERROR() MIKTEX_FATAL_ERROR("internal error")
1219
1220#define MIKTEX_UNEXPECTED() MIKTEX_INTERNAL_ERROR()
1221
1222#define MIKTEX_EXPECT(p) if (!(p)) { MIKTEX_UNEXPECTED(); }
1223
1224#define MIKTEX_FATAL_CRT_ERROR(functionName) \
1225 { \
1226 int errorCode = errno; \
1227 MiKTeX::Core::Session::FatalCrtError(functionName, errorCode, MiKTeX::Core::MiKTeXException::KVMAP(), MIKTEX_SOURCE_LOCATION()); \
1228 }
1229
1230#define MIKTEX_FATAL_CRT_ERROR_2(functionName, ...) \
1231 { \
1232 int errorCode = errno; \
1233 MiKTeX::Core::Session::FatalCrtError(functionName, errorCode, MiKTeX::Core::MiKTeXException::KVMAP(__VA_ARGS__), MIKTEX_SOURCE_LOCATION()); \
1234 }
1235
1236#define MIKTEX_FATAL_CRT_RESULT(functionName, errorCode) \
1237 MiKTeX::Core::Session::FatalCrtError(functionName, errorCode, MiKTeX::Core::MiKTeXException::KVMAP(), MIKTEX_SOURCE_LOCATION());
1238
1239#define MIKTEX_FATAL_CRT_RESULT_2(functionName, errorCode, ...) \
1240 MiKTeX::Core::Session::FatalCrtError(functionName, errorCode, MiKTeX::Core::MiKTeXException::KVMAP(__VA_ARGS__), MIKTEX_SOURCE_LOCATION());
1241
1242#if defined(MIKTEX_WINDOWS)
1243
1244#define MIKTEX_FATAL_WINDOWS_ERROR(functionName) \
1245 { \
1246 unsigned long errorCode = GetLastError(); \
1247 MiKTeX::Core::Session::FatalWindowsError(functionName, errorCode, "", "", "", MiKTeX::Core::MiKTeXException::KVMAP(), MIKTEX_SOURCE_LOCATION()); \
1248 }
1249
1250#define MIKTEX_FATAL_WINDOWS_ERROR_2(functionName, ...) \
1251 { \
1252 unsigned long errorCode = GetLastError(); \
1253 MiKTeX::Core::Session::FatalWindowsError(functionName, errorCode, "", "", "", MiKTeX::Core::MiKTeXException::KVMAP(__VA_ARGS__), MIKTEX_SOURCE_LOCATION()); \
1254 }
1255
1256#define MIKTEX_FATAL_WINDOWS_ERROR_3(functionName, description, ...) \
1257 { \
1258 unsigned long errorCode = GetLastError(); \
1259 MiKTeX::Core::Session::FatalWindowsError(functionName, errorCode, description, "", "", MiKTeX::Core::MiKTeXException::KVMAP(__VA_ARGS__), MIKTEX_SOURCE_LOCATION()); \
1260 }
1261
1262#define MIKTEX_FATAL_WINDOWS_ERROR_4(functionName, description, remedy, ...) \
1263 { \
1264 unsigned long errorCode = GetLastError(); \
1265 MiKTeX::Core::Session::FatalWindowsError(functionName, errorCode, description, remedy, "", MiKTeX::Core::MiKTeXException::KVMAP(__VA_ARGS__), MIKTEX_SOURCE_LOCATION()); \
1266 }
1267
1268#define MIKTEX_FATAL_WINDOWS_ERROR_5(functionName, description, remedy, tag, ...) \
1269 { \
1270 unsigned long errorCode = GetLastError(); \
1271 MiKTeX::Core::Session::FatalWindowsError(functionName, errorCode, description, remedy, tag, MiKTeX::Core::MiKTeXException::KVMAP(__VA_ARGS__), MIKTEX_SOURCE_LOCATION()); \
1272 }
1273
1274#define MIKTEX_FATAL_WINDOWS_RESULT(functionName, errorCode) \
1275 MiKTeX::Core::Session::FatalWindowsError(functionName, errorCode, "", "", "", MiKTeX::Core::MiKTeXException::KVMAP(), MIKTEX_SOURCE_LOCATION())
1276
1277#define MIKTEX_FATAL_WINDOWS_RESULT_2(functionName, errorCode, ...) \
1278 MiKTeX::Core::Session::FatalWindowsError(functionName, errorCode, "", "", "", MiKTeX::Core::MiKTeXException::KVMAP(__VA_ARGS__), MIKTEX_SOURCE_LOCATION())
1279
1280#define MIKTEX_FATAL_WINDOWS_RESULT_3(functionName, errorCode, description, ...) \
1281 MiKTeX::Core::Session::FatalWindowsError(functionName, errorCode, description, "", "", MiKTeX::Core::MiKTeXException::KVMAP(__VA_ARGS__), MIKTEX_SOURCE_LOCATION())
1282
1283#define MIKTEX_FATAL_WINDOWS_RESULT_4(functionName, errorCode, description, remedy, ...) \
1284 MiKTeX::Core::Session::FatalWindowsError(functionName, errorCode, description, remedy, "", MiKTeX::Core::MiKTeXException::KVMAP(__VA_ARGS__), MIKTEX_SOURCE_LOCATION())
1285
1286#define MIKTEX_FATAL_WINDOWS_RESULT_5(functionName, errorCode, description, remedy, tag, ...) \
1287 MiKTeX::Core::Session::FatalWindowsError(functionName, errorCode, description, remedy, tag, MiKTeX::Core::MiKTeXException::KVMAP(__VA_ARGS__), MIKTEX_SOURCE_LOCATION())
1288
1289#endif
1290
1291#endif
TriState
Tri-state enum class.
Definition: TriState.h:22
The MiKTeX ConfigurationProvider interface.
Definition: ConfigurationProvider.h:89
Definition: HasNamedValues.h:23
Find file callback interface.
Definition: Session.h:370
virtual bool TryCreateFile(const MiKTeX::Util::PathName &fileName, FileType fileType)=0
virtual bool InstallPackage(const std::string &packageId, const MiKTeX::Util::PathName &trigger, MiKTeX::Util::PathName &installRoot)=0
Run process callback interface.
Definition: Process.h:47
Extended initialization options.
Definition: Session.h:436
std::string GetTraceFlags() const
Definition: Session.h:533
void SetTraceCallback(MiKTeX::Trace::TraceCallback *callback)
Definition: Session.h:540
void SetProgramInvocationName(const std::string &programInvocationName)
Definition: Session.h:484
std::string GetProgramInvocationName() const
Definition: Session.h:491
void SetOptions(InitOptionSet options)
Definition: Session.h:463
void AddOption(InitOption option)
Definition: Session.h:477
InitInfo(const std::string &programInvocationName)
Definition: Session.h:447
InitOptionSet GetOptions() const
Definition: Session.h:470
MiKTeX::Trace::TraceCallback * GetTraceCallback()
Definition: Session.h:547
std::string GetTheNameOfTheGame() const
Definition: Session.h:505
void SetTheNameOfTheGame(const std::string &theNameOfTheGame)
Definition: Session.h:498
StartupConfig GetStartupConfig() const
Definition: Session.h:519
InitInfo(const std::string &programInvocationName, InitOptionSet options)
Definition: Session.h:455
void SetTraceFlags(const std::string &traceFlags)
Definition: Session.h:526
void SetStartupConfig(const StartupConfig &startupConfig)
Definition: Session.h:512
The MiKTeX session interface.
Definition: Session.h:403
virtual bool GetFontInfo(const std::string &fontName, std::string &supplier, std::string &typeface, double *genSize)=0
virtual bool FindFile(const std::string &fileName, const std::string &searchPath, MiKTeX::Util::PathName &result)=0
virtual int RunPerl(int argc, const char **argv)=0
virtual void ConfigureFile(const MiKTeX::Util::PathName &pathIn, const MiKTeX::Util::PathName &pathOut, MiKTeX::Configuration::HasNamedValues *callback=nullptr)=0
virtual bool GetPaperSizeInfo(int idx, PaperSizeInfo &paperSize)=0
virtual bool IsAdminMode()=0
virtual bool ConvertToBitmapFile(const MiKTeX::Util::PathName &sourceFileName, MiKTeX::Util::PathName &destFileName, IRunProcessCallback *callback)=0
virtual void SetLanguageInfo(const LanguageInfo &languageInfo)=0
virtual MiKTeX::Util::PathName GetMyLocation(bool canonicalized)=0
virtual void SetFormatInfo(const FormatInfo &formatInfo)=0
virtual std::vector< FileInfoRecord > GetFileInfoRecords()=0
virtual int RunPython(int argc, const char **argv)=0
virtual void ScheduleSystemCommand(const std::string &commandLine)=0
virtual FileTypeInfo GetFileTypeInfo(FileType fileType)=0
virtual PaperSizeInfo GetPaperSizeInfo(const std::string &dvipsName)=0
static void FatalCrtError(const std::string &functionName, int errorCode, const MiKTeXException::KVMAP &info, const SourceLocation &sourceLocation)
virtual std::vector< std::string > GetAllowedShellCommands()=0
virtual bool FindFile(const std::string &fileName, FileType fileType, FindFileOptionSet options, MiKTeX::Util::PathName &result)=0
MiKTeX::Util::OptionSet< InitOption > InitOptionSet
Init flags enum.
Definition: Session.h:432
virtual LocateResult Locate(const std::string &fileName, const LocateOptions &options)=0
virtual bool GetMakeFontsFlag()=0
virtual bool ShowManualPageAndWait(HWND hWnd, unsigned long topic)=0
virtual bool FindFile(const std::string &fileName, const std::string &searchPath, std::vector< MiKTeX::Util::PathName > &result)=0
virtual bool FindFile(const std::string &fileName, const std::string &searchPath, FindFileOptionSet options, std::vector< MiKTeX::Util::PathName > &result)=0
virtual MiKTeX::Util::PathName GetGhostscript(unsigned long *versionNumber)=0
virtual std::string Expand(const std::string &toBeExpanded, MiKTeX::Configuration::HasNamedValues *callback)=0
virtual bool FindFile(const std::string &fileName, FileType fileType, MiKTeX::Util::PathName &result)=0
virtual int RunJava(int argc, const char **argv)=0
virtual MiKTeX::Util::PathName GetMyProgramFile(bool canonicalized)=0
virtual void RecordFileInfo(const MiKTeX::Util::PathName &path, FileAccess access)=0
static std::shared_ptr< Session > Create(const InitInfo &initInfo)
virtual std::vector< FormatInfo > GetFormats()=0
virtual std::vector< std::string > MakeMakePkCommandLine(const std::string &fontName, int dpi, int baseDpi, const std::string &mfMode, MiKTeX::Util::PathName &fileName, MiKTeX::Configuration::TriState enableInstaller)=0
static void FatalWindowsError(const std::string &functionName, unsigned long errorCode, const std::string &description, const std::string &remedy, const std::string &tag, const MiKTeXException::KVMAP &info, const SourceLocation &sourceLocation)
virtual void SetFindFileCallback(IFindFileCallback *callback)=0
virtual std::tuple< ExamineCommandLineResult, std::string, std::string > ExamineCommandLine(const std::string &commandLine)=0
virtual std::vector< std::string > GetFontDirectories()=0
virtual bool IsFileAlreadyOpen(const MiKTeX::Util::PathName &fileName)=0
ExamineCommandLineResult
Result of a command-line examination.
Definition: Session.h:1150
virtual bool StartFileInfoRecorder()=0
virtual bool EnableFontMaker(bool enable)=0
virtual std::vector< FileTypeInfo > GetFileTypes()=0
virtual int RunBatch(int argc, const char **argv)=0
virtual std::string GetExpandedSearchPath(FileType fileType)=0
FindFileOption
Find file options.
Definition: Session.h:407
virtual bool FindFile(const std::string &fileName, FileType fileType, FindFileOptionSet options, std::vector< MiKTeX::Util::PathName > &result)=0
virtual void SetDefaultPaperSize(const std::string &dvipsName)=0
virtual std::string Expand(const std::string &toBeExpanded)=0
virtual void SetRecorderPath(const MiKTeX::Util::PathName &path)=0
virtual std::vector< LanguageInfo > GetLanguages()=0
virtual void DeleteFormatInfo(const std::string &key)=0
virtual bool StartFileInfoRecorder(bool recordPackageNames)=0
virtual bool FindPkFile(const std::string &fontName, const std::string &mfMode, int dpi, MiKTeX::Util::PathName &result)=0
virtual SetupConfig GetSetupConfig()=0
virtual std::string Expand(const std::string &toBeExpanded, ExpandOptionSet options, MiKTeX::Configuration::HasNamedValues *callback)=0
virtual int RunExe(int argc, const char **argv)=0
static std::shared_ptr< Session > TryGet()
virtual void SetTheNameOfTheGame(const std::string &name)=0
virtual bool TryGetFormatInfo(const std::string &key, FormatInfo &formatInfo)=0
static void FatalMiKTeXError(const std::string &message, const std::string &description, const std::string &remedy, const std::string &tag, const MiKTeXException::KVMAP &info, const SourceLocation &sourceLocation)
virtual MiKTeX::Util::PathName GetMyPrefix(bool canonicalized)=0
virtual bool RunningAsAdministrator()=0
virtual void ConfigureFile(const MiKTeX::Util::PathName &pathRel, MiKTeX::Configuration::HasNamedValues *callback=nullptr)=0
virtual int RunGhostscript(int argc, const char **argv)=0
virtual void SplitFontPath(const MiKTeX::Util::PathName &fontPath, std::string *fontType, std::string *supplier, std::string *typeface, std::string *fontName, std::string *pointSize)=0
virtual void SetAdminMode(bool adminMode, bool force=false)=0
virtual bool FindFile(const std::string &fileName, const std::string &searchPath, FindFileOptionSet options, MiKTeX::Util::PathName &result)=0
virtual ShellCommandMode GetShellCommandMode()=0
virtual bool FindFile(const std::string &fileName, FileType fileType, std::vector< MiKTeX::Util::PathName > &result)=0
virtual bool IsUserAnAdministrator()=0
InitOption
Initialization options.
Definition: Session.h:422
virtual void ScheduleFileRemoval(const MiKTeX::Util::PathName &path)=0
virtual bool IsSharedSetup()=0
virtual bool FindTfmFile(const std::string &fontName, MiKTeX::Util::PathName &result, bool create)=0
virtual FileType DeriveFileType(const MiKTeX::Util::PathName &fileName)=0
virtual bool TryCreateFromTemplate(const MiKTeX::Util::PathName &path)=0
virtual FormatInfo GetFormatInfo(const std::string &key)=0
Definition: TraceCallback.h:45
bool Empty() const
Definition: CharBuffer.h:239
Definition: OptionSet.h:37
Instances of this class can be used to store path names.
Definition: PathName.h:73
ConfigurationScope
MiKTeX configuration scope.
Definition: Session.h:103
@ User
User configuration scope.
@ Common
Common (system-wide) configuration scope.
FileAccess
File access options.
Definition: File.h:72
ShellCommandMode
Shell command mode.
Definition: Session.h:357
@ Forbidden
Shell commands are forbidden.
@ Unrestricted
All shell commands are allowed.
@ Restricted
Only some shell commands are allowed.
constexpr unsigned INVALID_ROOT_INDEX
An invalid TEXMF root index.
Definition: Session.h:75
FileMode
How to open a file.
Definition: File.h:54
@ Create
The file will be created, if it doesn't already exist.
MiKTeXConfiguration
MiKTeX configurations.
Definition: Session.h:79
@ Regular
Regular MiKTeX configuration.
@ Direct
MiKTeXDirect (CD/DVD) configuration.
@ Portable
MiKTeX Portable configuration.
ExpandOption
Expansion options.
Definition: Session.h:329
@ PathPatterns
Expand path patterns.
FileType
File type enum class.
Definition: FileType.h:33
RegisterRootDirectoriesOption
Root registration options.
Definition: Session.h:342
@ Temporary
Only temporary registration.
@ Review
Check if the registration is valid.
File information.
Definition: Session.h:257
File type information.
Definition: Session.h:240
std::vector< std::string > alternateExtensions
Extra list of file name extensions associated with the file type.
Definition: Session.h:248
std::vector< std::string > searchPath
Search path for files.
Definition: Session.h:250
std::vector< std::string > envVarNames
List of environment variable names.
Definition: Session.h:252
std::string fileTypeString
The file type as a string.
Definition: Session.h:244
std::vector< std::string > fileNameExtensions
List of file name extensions associated with the file type.
Definition: Session.h:246
Information about a TeX format.
Definition: Session.h:287
std::string name
Name of the format.
Definition: Session.h:291
std::string description
One-line description.
Definition: Session.h:293
std::string compiler
The compiler (engine) which processes the format.
Definition: Session.h:295
std::string key
The access key.
Definition: Session.h:289
std::vector< std::string > arguments
Extra engine arguments.
Definition: Session.h:309
std::string preloaded
The name of another format which has to be pre-loaded.
Definition: Session.h:301
std::string inputFile
The name of the input file.
Definition: Session.h:297
std::string outputFile
The name of the output file.
Definition: Session.h:299
Language information.
Definition: Session.h:314
Definition: Session.h:386
Definition: Session.h:396
METAFONT mode.
Definition: Session.h:231
User information.
Definition: Session.h:265
Paper size information.
Definition: Session.h:214
int height
Paper height (in 72nds of an inch).
Definition: Session.h:226
std::string name
Paper name (e.g., A4)
Definition: Session.h:218
int width
Paper width (in 72nds of an inch).
Definition: Session.h:223
Definition: RootDirectoryInfo.h:35
Information about an open file.
Definition: Session.h:563
Definition: Session.h:206
Definition: Exceptions.h:38
Startup configuration.
Definition: Session.h:124
MiKTeX::Util::PathName userInstallRoot
User installation root directory.
Definition: Session.h:132
MiKTeX::Util::PathName commonConfigRoot
System-wide configuration root directory.
Definition: Session.h:141
std::string otherUserRoots
User root directories defined by other TeX systems.
Definition: Session.h:138
MiKTeXConfiguration config
The MiKTeX configuration type.
Definition: Session.h:156
std::string otherCommonRoots
System-wide root directories defined by other TeX systems.
Definition: Session.h:153
MiKTeX::Util::PathName userDataRoot
User data root directory.
Definition: Session.h:129
MiKTeX::Util::PathName commonInstallRoot
System-wide installation root directory.
Definition: Session.h:147
MiKTeX::Util::PathName commonDataRoot
System-wide data root directory.
Definition: Session.h:144
std::string commonRoots
Additional TEXMF root defined by the admin.
Definition: Session.h:150
MiKTeX::Util::PathName userConfigRoot
User configuration root directory.
Definition: Session.h:126
std::string userRoots
Additional TEXMF roots defined by the user.
Definition: Session.h:135
An instance of this struct represents a version number.
Definition: VersionNumber.h:36