cosmetix
[xreader.git] / xreadercfg.d
blob14ff752132a88f9b2d87c3499a20c537897b7f04
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.nanovg;
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;
70 __gshared NVGColor colorDim = NVGColor(0, 0, 0, 0);
71 __gshared NVGColor colorBack = NVGColor(0x2a, 0x2a, 0x2a);
72 __gshared NVGColor colorText = NVGColor(0xff, 0x7f, 0x00);
73 __gshared NVGColor colorTextHi = NVGColor(0xff, 0xff, 0x00);
74 __gshared NVGColor colorTextHref = NVGColor(0, 0, 0x80);
76 __gshared int uiFont, galmapFont;
77 __gshared int textFont, textiFont, textbFont, textzFont;
78 __gshared int monoFont, monoiFont, monobFont, monozFont;
80 __gshared bool optJustify = false;
83 enum MinWinWidth = 320;
84 enum MinWinHeight = 240;
87 // ////////////////////////////////////////////////////////////////////////// //
88 BookInfo[] loadDetailedHistory () {
89 BookInfo[] res;
90 try {
91 import std.path;
92 foreach (string line; VFile(buildPath(RcDir, ".lastfile")).byLineCopy) {
93 line = xstrip(line);
94 if (line.length == 0 || line[0] == '#' || line[0] == ';') continue;
95 try {
96 res ~= loadBookInfo(line);
97 res[$-1].diskfile = line.idup;
98 } catch (Exception) {}
100 } catch (Exception) {}
101 return res;
105 // ////////////////////////////////////////////////////////////////////////// //
106 __gshared string[] eliteShipFiles;
109 void loadEliteShips () {
110 import std.path;
111 import std.path : extension;
112 vfsAddPak(buildPath(RcDir, "eliteships.zip"), "oxm:");
113 //scope(exit) vfsRemovePack(buildPath(RcDir, "eliteships.zip"), "oxm:");
114 foreach (immutable idx, ref de; vfsFileList) {
115 //writeln("<", de.name, ">");
116 if (de.name.length > 4 && de.name[0..4] == "oxm:" && strEquCI(de.name.extension, ".oxm")) {
118 import core.memory : GC;
119 try {
120 auto mdl = new EliteModel(de.name);
121 mdl.freeData();
122 mdl.destroy;
123 //eliteShips ~= mdl;
124 eliteShipFiles ~= de.name;
125 } catch (Exception e) {}
126 GC.collect();
128 eliteShipFiles ~= de.name;
134 // ////////////////////////////////////////////////////////////////////////// //
135 VFile fwritef(A...) (VFile fl, string fmt, /*lazy*/ A args) {
136 import std.string : format;
137 auto s = format(fmt, args);
138 if (s.length) fl.rawWriteExact(s[]);
139 return fl;
143 // ////////////////////////////////////////////////////////////////////////// //
144 void readConfig () {
145 import std.path;
146 VFile fl;
147 try {
148 fl = VFile(buildPath(RcDir, ".config.ui"));
149 } catch (Exception) {
150 try {
151 try { import std.file; mkdirRecurse(RcDir); } catch (Exception) {}
152 fl = VFile(buildPath(RcDir, ".config.ui"), "w");
153 fl.fwritef("width=%s\n", GWidth);
154 fl.fwritef("height=%s\n", GHeight);
155 fl.fwritef("font-text=%s\n", textFontName);
156 fl.fwritef("font-text-italic=%s\n", textiFontName);
157 fl.fwritef("font-text-bold=%s\n", textbFontName);
158 fl.fwritef("font-text-bold-italic=%s\n", textzFontName);
159 fl.fwritef("font-mono=%s\n", monoFontName);
160 fl.fwritef("font-mono-italic=%s\n", monoiFontName);
161 fl.fwritef("font-mono-bold=%s\n", monobFontName);
162 fl.fwritef("font-mono-bold-italic=%s\n", monozFontName);
163 fl.fwritef("font-ui=%s\n", uiFontName);
164 fl.fwritef("font-galmap=%s\n", galmapFontName);
165 fl.fwritef("text-size=%s\n", fsizeText);
166 fl.fwritef("ui-text-size=%s\n", fsizeUI);
167 fl.fwritef("galmap-text-size=%s\n", fGalMapSize);
168 fl.fwritef("scrollbar-on-left=%s\n", sbLeft);
169 fl.fwritef("interference=%s\n", interAllowed);
170 fl.fwritef("color-dim=0x%08x\n", colorDim.asUintHtml);
171 fl.fwritef("color-back=0x%08x\n", colorBack.asUintHtml);
172 fl.fwritef("color-text=0x%08x\n", colorText.asUintHtml);
173 fl.fwritef("color-text-hi=0x%08x\n", colorTextHi.asUintHtml);
174 fl.fwritef("color-text-href=0x%08x\n", colorTextHref.asUintHtml);
175 fl.fwritef("nano-aa=%s\n", flagNanoAA);
176 fl.fwritef("nano-ss=%s\n", flagNanoSS);
177 fl.fwritef("justify-text=%s\n", optJustify);
178 } catch (Exception) {}
179 return;
181 xiniParse(fl,
182 "font-text", &textFontName,
183 "font-text-italic", &textiFontName,
184 "font-text-bold", &textbFontName,
185 "font-text-bold-italic", &textzFontName,
186 "font-text-italic-bold", &textzFontName,
187 "font-mono", &monoFontName,
188 "font-mono-italic", &monoiFontName,
189 "font-mono-bold", &monobFontName,
190 "font-mono-bold-italic", &monozFontName,
191 "font-mono-italic-bold", &monozFontName,
192 "font-ui", &uiFontName,
193 "font-galmap", &galmapFontName,
194 "width", &GWidth,
195 "height", &GHeight,
196 "text-size", &fsizeText,
197 "ui-text-size", &fsizeUI,
198 "galmap-text-size", &fGalMapSize,
199 "scrollbar-on-left", &sbLeft,
200 "interference", &interAllowed,
201 "color-dim", &colorDim,
202 "color-back", &colorBack,
203 "color-text", &colorText,
204 "color-text-hi", &colorTextHi,
205 "color-text-href", &colorTextHref,
206 "nano-aa", &flagNanoAA,
207 "nano-ss", &flagNanoSS,
208 "justify-text", &optJustify,
213 // ////////////////////////////////////////////////////////////////////////// //
214 bool isComment (const(char)[] s) {
215 while (s.length && s.ptr[0] <= ' ') s = s[1..$];
216 return (s.length > 0 && s.ptr[0] == '#');