added support for onion flibusta urls
[xreader.git] / xreadercfg.d
blobab782efa947910db735cd628d24e626621c022f8
1 /* Written by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
2 * Understanding is not required. Only obedience.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 module xreadercfg;
19 import arsd.simpledisplay;
20 import arsd.image;
22 import iv.nanovega;
23 import iv.strex;
24 import iv.vfs;
25 import iv.vfs.io;
27 import xiniz;
28 import xmodel;
29 import booktext;
32 // ////////////////////////////////////////////////////////////////////////// //
33 __gshared string RcDir = "~/.xreader";
34 __gshared string stateFileName;
36 shared static this () {
37 import std.path;
38 RcDir = RcDir.expandTilde.absolutePath;
39 //writeln(RcDir);
42 __gshared float shipAngle = 0;
43 __gshared bool showShip = false;
45 __gshared EliteModel shipModel;
48 // ////////////////////////////////////////////////////////////////////////// //
49 __gshared string textFontName = "~/ttf/ms/arial.ttf:noaa";
50 __gshared string textiFontName = "~/ttf/ms/ariali.ttf:noaa";
51 __gshared string textbFontName = "~/ttf/ms/arialbd.ttf:noaa";
52 __gshared string textzFontName = "~/ttf/ms/arialbi.ttf:noaa";
53 __gshared string monoFontName = "~/ttf/ms/cour.ttf:noaa";
54 __gshared string monoiFontName = "~/ttf/ms/couri.ttf:noaa";
55 __gshared string monobFontName = "~/ttf/ms/courbd.ttf:noaa";
56 __gshared string monozFontName = "~/ttf/ms/courbi.ttf:noaa";
57 __gshared string uiFontName = "~/ttf/ms/verdana.ttf:noaa";
58 __gshared string galmapFontName = "~/ttf/ms/verdana.ttf:noaa";
59 __gshared int GWidth = 900;
60 __gshared int GHeight = 1024;
61 __gshared int fsizeText = 24;
62 __gshared int fsizeUI = 16;
63 __gshared int fGalMapSize = 16;
64 __gshared bool sbLeft = false;
65 __gshared bool interAllowed = false;
67 __gshared bool flagNanoAA = false;
68 __gshared bool flagNanoSS = false;
69 __gshared bool flagNanoFAA = false;
71 __gshared NVGColor colorDim = NVGColor(0, 0, 0, 0);
72 __gshared NVGColor colorBack = NVGColor(0x2a, 0x2a, 0x2a);
73 __gshared NVGColor colorText = NVGColor(0xff, 0x7f, 0x00);
74 __gshared NVGColor colorTextHi = NVGColor(0xff, 0xff, 0x00);
75 __gshared NVGColor colorTextHref = NVGColor(0, 0, 0x80);
77 __gshared int uiFont, galmapFont;
78 __gshared int textFont, textiFont, textbFont, textzFont;
79 __gshared int monoFont, monoiFont, monobFont, monozFont;
81 __gshared bool optJustify = false;
84 enum MinWinWidth = 320;
85 enum MinWinHeight = 240;
88 // ////////////////////////////////////////////////////////////////////////// //
89 BookInfo[] loadDetailedHistory () {
90 BookInfo[] res;
91 try {
92 import std.path, std.file : exists;
93 int count = 0;
94 string[] lines;
95 foreach (string line; VFile(buildPath(RcDir, ".lastfile")).byLineCopy) {
96 ++count;
97 auto oline = line;
98 line = xstrip(line);
99 if (line.length == 0 || line[0] == '#' || line[0] == ';') {
100 lines ~= oline;
101 continue;
103 try {
104 res ~= loadBookInfo(line);
105 res[$-1].diskfile = line.idup;
106 lines ~= oline;
107 } catch (Exception) {}
109 // something was changed?
110 if (count != lines.length) {
111 // yes, rewrite file
112 auto fo = VFile(buildPath(RcDir, ".lastfile"), "w");
113 foreach (string s; lines) fo.writeln(s);
115 } catch (Exception) {}
116 return res;
120 void removeFileFromHistory (const(char)[] filename) {
121 try {
122 import std.path;
123 string[] lines;
124 foreach (string line; VFile(buildPath(RcDir, ".lastfile")).byLineCopy) {
125 if (line.xstrip != filename) lines ~= line;
127 auto fo = VFile(buildPath(RcDir, ".lastfile"), "w");
128 foreach (string s; lines) fo.writeln(s);
129 } catch (Exception) {}
133 // ////////////////////////////////////////////////////////////////////////// //
134 __gshared string[] eliteShipFiles;
137 void loadEliteShips () {
138 import std.path;
139 import std.path : extension;
140 vfsAddPak(buildPath(RcDir, "eliteships.zip"), "oxm:");
141 //scope(exit) vfsRemovePak(buildPath(RcDir, "eliteships.zip"), "oxm:");
142 foreach (immutable idx, ref de; vfsFileList) {
143 //writeln("<", de.name, ">");
144 if (de.name.length > 4 && de.name[0..4] == "oxm:" && strEquCI(de.name.extension, ".oxm")) {
146 import core.memory : GC;
147 try {
148 auto mdl = new EliteModel(de.name);
149 mdl.freeData();
150 mdl.destroy;
151 //eliteShips ~= mdl;
152 eliteShipFiles ~= de.name;
153 } catch (Exception e) {}
154 GC.collect();
156 eliteShipFiles ~= de.name;
162 // ////////////////////////////////////////////////////////////////////////// //
163 VFile fwritef(A...) (VFile fl, string fmt, /*lazy*/ A args) {
164 import std.string : format;
165 auto s = format(fmt, args);
166 if (s.length) fl.rawWriteExact(s[]);
167 return fl;
171 // ////////////////////////////////////////////////////////////////////////// //
172 void readConfig () {
173 import std.path;
174 VFile fl;
175 try {
176 fl = VFile(buildPath(RcDir, ".config.ui"));
177 } catch (Exception) {
178 try {
179 try { import std.file; mkdirRecurse(RcDir); } catch (Exception) {}
180 fl = VFile(buildPath(RcDir, ".config.ui"), "w");
181 fl.fwritef("width=%s\n", GWidth);
182 fl.fwritef("height=%s\n", GHeight);
183 fl.fwritef("font-text=%s\n", textFontName);
184 fl.fwritef("font-text-italic=%s\n", textiFontName);
185 fl.fwritef("font-text-bold=%s\n", textbFontName);
186 fl.fwritef("font-text-bold-italic=%s\n", textzFontName);
187 fl.fwritef("font-mono=%s\n", monoFontName);
188 fl.fwritef("font-mono-italic=%s\n", monoiFontName);
189 fl.fwritef("font-mono-bold=%s\n", monobFontName);
190 fl.fwritef("font-mono-bold-italic=%s\n", monozFontName);
191 fl.fwritef("font-ui=%s\n", uiFontName);
192 fl.fwritef("font-galmap=%s\n", galmapFontName);
193 fl.fwritef("text-size=%s\n", fsizeText);
194 fl.fwritef("ui-text-size=%s\n", fsizeUI);
195 fl.fwritef("galmap-text-size=%s\n", fGalMapSize);
196 fl.fwritef("scrollbar-on-left=%s\n", sbLeft);
197 fl.fwritef("interference=%s\n", interAllowed);
198 fl.fwritef("color-dim=0x%08x\n", colorDim.asUintARGB);
199 fl.fwritef("color-back=0x%08x\n", colorBack.asUintARGB);
200 fl.fwritef("color-text=0x%08x\n", colorText.asUintARGB);
201 fl.fwritef("color-text-hi=0x%08x\n", colorTextHi.asUintARGB);
202 fl.fwritef("color-text-href=0x%08x\n", colorTextHref.asUintARGB);
203 fl.fwritef("nano-aa=%s\n", flagNanoAA);
204 fl.fwritef("nano-ss=%s\n", flagNanoSS);
205 fl.fwritef("nano-faa=%s\n", flagNanoFAA);
206 fl.fwritef("justify-text=%s\n", optJustify);
207 } catch (Exception) {}
208 return;
210 xiniParse(fl,
211 "font-text", &textFontName,
212 "font-text-italic", &textiFontName,
213 "font-text-bold", &textbFontName,
214 "font-text-bold-italic", &textzFontName,
215 "font-text-italic-bold", &textzFontName,
216 "font-mono", &monoFontName,
217 "font-mono-italic", &monoiFontName,
218 "font-mono-bold", &monobFontName,
219 "font-mono-bold-italic", &monozFontName,
220 "font-mono-italic-bold", &monozFontName,
221 "font-ui", &uiFontName,
222 "font-galmap", &galmapFontName,
223 "width", &GWidth,
224 "height", &GHeight,
225 "text-size", &fsizeText,
226 "ui-text-size", &fsizeUI,
227 "galmap-text-size", &fGalMapSize,
228 "scrollbar-on-left", &sbLeft,
229 "interference", &interAllowed,
230 "color-dim", &colorDim,
231 "color-back", &colorBack,
232 "color-text", &colorText,
233 "color-text-hi", &colorTextHi,
234 "color-text-href", &colorTextHref,
235 "nano-aa", &flagNanoAA,
236 "nano-ss", &flagNanoSS,
237 "nano-faa", &flagNanoFAA,
238 "justify-text", &optJustify,
243 // ////////////////////////////////////////////////////////////////////////// //
244 bool isComment (const(char)[] s) {
245 while (s.length && s.ptr[0] <= ' ') s = s[1..$];
246 return (s.length > 0 && s.ptr[0] == '#');