1 | lib 1400521 // FlatLAF |
2 | |
3 | set flag PingV3. |
4 | set flag NotifyingPrintLog. |
5 | set flag SymbolAsString. |
6 | |
7 | // Do the JavaX init |
8 | svoid standaloneInit {
|
9 | __javax = x30.class; |
10 | x30.__javax = x30.class; // for hotwire |
11 | x30_pkg.x30_util.__setJavaX(x30.class); |
12 | x30.cleanKillMsg = ""; |
13 | callOnLoadMethods(mc()); |
14 | } |
15 | |
16 | concept PrintLogModule > DynPrintLog {
|
17 | start { setModuleName("Log"); }
|
18 | |
19 | S getPrintLog() {
|
20 | ret printLog(); |
21 | } |
22 | |
23 | bool useErrorHandling() { false; }
|
24 | } |
25 | |
26 | concept Stem {
|
27 | transient GazelleHost host; |
28 | DynModule module; |
29 | Rect frameRect; |
30 | bool minimized, maximized, alwaysOnTop, autoUpdate, minimizeToTray; |
31 | |
32 | LS fieldsToShareBetweenDatabases() {
|
33 | ret identifiers("frameRect, minimized, maximized, alwaysOnTop, autoUpdate, minimizeToTray");
|
34 | } |
35 | |
36 | transient JFrame window; |
37 | transient JButton btnMax; |
38 | transient JLabel titleComponent; |
39 | transient gettable JButton compileButton; |
40 | //transient bool autoUpdateDisabled; |
41 | |
42 | *() {}
|
43 | *(GazelleHost *host) {}
|
44 | *(GazelleHost *host, DynModule *module) {}
|
45 | |
46 | Rect getFrameRect() {
|
47 | ret toRect(getBounds(window)); |
48 | } |
49 | |
50 | void saveFrameRect {
|
51 | setField(frameRect := getFrameRect()); |
52 | } |
53 | |
54 | void setAlwaysOnTop(bool alwaysOnTop) {
|
55 | this.alwaysOnTop = alwaysOnTop; |
56 | change(); |
57 | alwaysOnTop(window, alwaysOnTop); |
58 | } |
59 | |
60 | void setMinimizeToTray(bool minimizeToTray) {
|
61 | cset(this, +minimizeToTray); |
62 | } |
63 | |
64 | void setWindow(JFrame window) {
|
65 | this.window = window; |
66 | if (frameRect != null) |
67 | setBounds(window, frameRect); |
68 | //onWindowClosing(window, -> host.cleanExit()); |
69 | onBoundsChange(window, r saveFrameRect); |
70 | alwaysOnTop(window, alwaysOnTop); |
71 | } |
72 | |
73 | void activateWindow {
|
74 | activateFrame_v3(window); |
75 | } |
76 | |
77 | bool isMain() { ret this == host.stem; }
|
78 | |
79 | void minimize {
|
80 | cset(this, minimized := true); |
81 | if (!minimizeToTray || host.trayIcon == null || !isMain()) |
82 | minimizeWindow(window); |
83 | else |
84 | hideWindow(window); |
85 | } |
86 | |
87 | void deleteMe {
|
88 | printAlsoToSystemOut = true; |
89 | print("deleteMe " + isMain());
|
90 | if (isMain()) {
|
91 | host.cleanExit(); |
92 | } else {
|
93 | cleanMeUp(); |
94 | } |
95 | } |
96 | |
97 | void cleanMeUp {
|
98 | disposeWindow(window); |
99 | dispose module; |
100 | cdelete(this); |
101 | } |
102 | |
103 | void grabWindowState {
|
104 | setField(maximized := !isExtendedStateNormal(window)); |
105 | } |
106 | |
107 | void updateBtnMax {
|
108 | if (!isShowing(btnMax)) ret; |
109 | grabWindowState(); |
110 | setText(btnMax, maximized ? "NORM" : "MAX"); |
111 | } |
112 | |
113 | JComponent makeWindowBorderAndTitle(JComponent contents, S title) {
|
114 | //ret jCenteredSection_fontSizePlus(10, title, vis); |
115 | |
116 | var icons = jline(); |
117 | if (host.allowFrameMaximization) {
|
118 | icons.add(btnMax = jbutton("", rThread {
|
119 | maximizeOrRestoreFrame(window); |
120 | updateBtnMax(); |
121 | })); |
122 | onFirstShowing(btnMax, r updateBtnMax); |
123 | } |
124 | |
125 | icons.add(toolTip("Minimize this window", jbutton("MIN", r minimize)));
|
126 | |
127 | if (isMain()) |
128 | icons.add(toolTip("Exit Gazelle", jbutton("QUIT", rThread {
|
129 | if (swingConfirm(window, "Really quit Gazelle?")) |
130 | deleteMe(); |
131 | }))); |
132 | else |
133 | icons.add(toolTip("Close this window", jbutton("X", rThread deleteMe)));
|
134 | |
135 | //setHorizontalMarginForAllButtons(icons, 4); |
136 | icons.add(jPopDownButton_noText(flattenToList( |
137 | |
138 | // always on top |
139 | |
140 | jCheckBoxMenuItem_dyn("Always on top",
|
141 | -> alwaysOnTop, |
142 | alwaysOnTop -> setAlwaysOnTop(alwaysOnTop)), |
143 | |
144 | // restart + update |
145 | |
146 | "---", |
147 | "Restart", rThread { host.restart() },
|
148 | "Update Gazelle", rThread { host.upgradeGazelle() },
|
149 | !isMain() ? null : jCheckBoxMenuItem_dyn("Auto-Update",
|
150 | -> autoUpdate, |
151 | b -> cset(Stem.this, autoUpdate := b)), |
152 | |
153 | // debugging + screenshooting gazelle |
154 | |
155 | "---", |
156 | !isMain() ? null : ll( |
157 | "Screenshoot this window", rThread shootWindow, |
158 | "Dump threads", rThread { showText("User threads", renderUserThreadsWithStackTraces()); },
|
159 | !isMain() ? null : "Log", !isMain() ? null : r { host.showPrintLog() },
|
160 | !isMain() ? null : "Copy log to clipboard", !isMain() ? null : rThread {
|
161 | copyToClipboard(printLog()); |
162 | infoBox("Copied log to clipboard");
|
163 | }, |
164 | ), |
165 | |
166 | ccallOpt(module, "popDownItems") |
167 | ))); |
168 | |
169 | JComponent actualTitle = titleComponent = fontSizePlus(7, jCenteredLabel(title)); |
170 | installWindowDragger(actualTitle); |
171 | |
172 | if (/*isMain() &&*/ haveMuricaPassword()) |
173 | actualTitle = centerAndEastWithMargin(actualTitle, |
174 | jline( |
175 | compileButton = makeCompileButton(), |
176 | jLiveValueLabel(host.lvComputerCount()) |
177 | )); |
178 | |
179 | var spacer = gazelle_wavySpacer(); |
180 | var titleBarMain = setOpaqueBackground(host.color1, |
181 | jtransparent_recursive(westCenterAndEastWithMargin( |
182 | jImage_scaledToHeight(24, host.trayIconImageID), |
183 | actualTitle, |
184 | setOpaqueBackground(host.color2, spacer))); |
185 | |
186 | installWindowDragger(spacer); |
187 | |
188 | var titleBar = setBackground(host.color2, centerAndEast( |
189 | titleBarMain, |
190 | icons)); |
191 | |
192 | var border = |
193 | // createBevelBorder(); |
194 | BorderFactory.createLineBorder(host.color1, host.borderSize); |
195 | |
196 | var outerPanel = withBorder(border, |
197 | northAndCenter(titleBar, contents)); |
198 | |
199 | installWindowResizeDraggerOnBorder(outerPanel); |
200 | ret outerPanel; |
201 | } |
202 | |
203 | JButton makeCompileButton() {
|
204 | var gears = resizeImageIcon(imageIcon(#1103061), 16); |
205 | |
206 | var btn = jimageButtonScaledToWidth(16, #1101268, "Compile & update", |
207 | rThread { host.compile() });
|
208 | //enableComponentAccordingToVar(host.compileButtonEnabled, btn); |
209 | |
210 | componentPopupMenuItem(btn, "Compile main library", rThread { host.compileUtils() });
|
211 | |
212 | ret btn; |
213 | } |
214 | |
215 | void startAndShow() {
|
216 | module._host = this; |
217 | setOpt_raw(module, +threadPool); // only if the field exists |
218 | setOpt_raw(module, concepts := host.concepts); |
219 | setOpt_raw(module, g22utils := host.g22utils); |
220 | copyLocalLog(module, mc()); |
221 | |
222 | var vis, title = unpair makeVisAndTitle(); |
223 | printWithMS("Show frame");
|
224 | |
225 | JFrame frame = makeUndecoratedFrame(title, vis); |
226 | setFrameIcon(frame, host.trayIconImageID); |
227 | setWindow(frame); |
228 | |
229 | frame.addPropertyChangeListener("title", evt ->
|
230 | setText(titleComponent, frame.getTitle())); |
231 | |
232 | if (minimized) minimize(); |
233 | onWindowDeiconified(frame, -> cset(this, minimized := false)); |
234 | |
235 | showWindow(window); |
236 | if (maximized && host.allowFrameMaximization) maximizeFrame(window); |
237 | } |
238 | |
239 | Pair<JComponent, S> makeVisAndTitle() {
|
240 | JComponent vis; |
241 | {
|
242 | printWithMS("Starting " + module);
|
243 | temp module.enter(); |
244 | module.start(); |
245 | |
246 | printWithMS("Visualize");
|
247 | vis = swing(-> {
|
248 | temp module.enter(); |
249 | ret module.visualize(); |
250 | }); |
251 | } |
252 | |
253 | S title = host.windowTitle; |
254 | if (!isMain()) |
255 | // title += appendWithColon(module.moduleName()); |
256 | title = unnull(module.moduleName()); |
257 | vis = makeWindowBorderAndTitle(vis, title); |
258 | ret pair(vis, title); |
259 | } |
260 | |
261 | void revisualize {
|
262 | if (window == null) ret; |
263 | |
264 | pcall {
|
265 | module.unvisualize(); |
266 | } |
267 | |
268 | var vis, title = unpair makeVisAndTitle(); |
269 | setFrameContents(window, vis); |
270 | } |
271 | |
272 | void shootWindow {
|
273 | var img = renderComponentToImage(window); |
274 | copyImageToClipboard(img); |
275 | saveInImageDirectoryWithCounter(gazelle22_imagesSubDirName() + "/Gazelle", img); |
276 | } |
277 | } // end of Stem |
278 | |
279 | // This replaces the Stefan's OS main class. It is not persisted |
280 | transient sclass GazelleHost is G22MasterStuff {
|
281 | Stem stem; |
282 | DynModule gazelle; |
283 | |
284 | transient S windowTitle = "November Gazelle v1"; |
285 | transient S trayIconImageID = #1103047; |
286 | transient int borderSize = 5; |
287 | transient Color color1 = awtColor("ADD8E6");
|
288 | transient Color color2 = awtColor("EEEEEE");
|
289 | transient Color color3 = awtColor("A3C0AA");
|
290 | transient IF0<DynModule> moduleMaker; |
291 | transient ThreadPool threadPool; |
292 | |
293 | transient TrayIcon trayIcon; |
294 | transient TrayIconLastPosition trayIconLastPosition; |
295 | |
296 | transient Set<S> argsSet; |
297 | transient bool incrementalDownloads = true; |
298 | |
299 | transient Concepts concepts; |
300 | |
301 | // This caused problems, disabled for now |
302 | transient bool allowFrameMaximization; |
303 | |
304 | transient StefansOS_ConnectToServer serverConnector; |
305 | transient ComputerCountListener computerCount; |
306 | |
307 | transient Q systemQ = startQ("System Q");
|
308 | |
309 | //transient BoolVarWithNotify compileButtonEnabled = new(true); |
310 | |
311 | transient new G22Utils g22utils; |
312 | |
313 | transient MapSO importedFieldsForMainStem; |
314 | |
315 | *(ThreadPool *threadPool, IF0<DynModule> *moduleMaker) {}
|
316 | |
317 | void trayIconLeftClick {
|
318 | activateFrame_v3(mainWindow()); |
319 | } |
320 | |
321 | void makeTrayIcon {
|
322 | pcall-short {
|
323 | trayIcon_imageAutoSize = false; |
324 | trayIcon = installTrayIcon(trayIconImageID, windowTitle, |
325 | r trayIconLeftClick, |
326 | "Show Gazelle", r trayIconLeftClick, |
327 | "Exit Gazelle", r cleanExit |
328 | ); |
329 | trayIconLastPosition = new TrayIconLastPosition(trayIcon); |
330 | } |
331 | } |
332 | |
333 | void run(S[] args) {
|
334 | try {
|
335 | run2(args); |
336 | } catch print e {
|
337 | //messageBox(e); |
338 | hideTrayIcon(trayIcon); |
339 | onWindowClosing(-> systemExit(1), getWindow( |
340 | showText_fast_noWrap("Gazelle Error", renderStackTrace(e))));
|
341 | //AutoVMExit.install(); |
342 | } |
343 | } |
344 | |
345 | void run2(S[] args) {
|
346 | argsSet = asSet(args); |
347 | |
348 | if (!argsSet.contains("noflatlaf"))
|
349 | com.formdev.flatlaf.FlatLightLaf.setup(); |
350 | |
351 | if (contains(args, "profile")) |
352 | profileToConsole(() -> actualMain(args)); |
353 | else |
354 | actualMain(args); |
355 | |
356 | if (argsSet.contains("brexit")) System.exit(0);
|
357 | } |
358 | |
359 | void actualMain(S... args) {
|
360 | vm_generalMap_put(stefansOS := this); |
361 | |
362 | System.out.println(hmsWithColonsAndMS() + ": Init"); |
363 | //x30.coreInit(); |
364 | |
365 | // Ready to roll |
366 | |
367 | printJavaVersion(); |
368 | |
369 | if (contains(argsSet, "profile")) |
370 | doEvery(1.0, r printRunningThreads); |
371 | |
372 | if (containsOneOf(argsSet, "upgrade", "update")) |
373 | ret with upgradeGazelle(); |
374 | |
375 | g22utils.masterStuff = this; |
376 | |
377 | makeTrayIcon(); |
378 | |
379 | initAutoUpdate(); |
380 | |
381 | IF1<S, Class> classFinder = makeClassFinder(); |
382 | |
383 | // Start DB |
384 | |
385 | S dbName = g22utils.dbToOpen(); |
386 | File conceptsFile = newFile(newFile(g22utils.databasesMotherDir(), dbName), conceptsFileName()); |
387 | concepts = newConceptsWithClassFinder(conceptsFile, classFinder); |
388 | startDBAndModules(); |
389 | } |
390 | |
391 | void startDBAndModules {
|
392 | concepts.makeStructureData = -> {
|
393 | structure_Data data = concepts.makeStructureData_base(); |
394 | data.mcDollar = mcDollar(); |
395 | ret data; |
396 | }; |
397 | try {
|
398 | concepts.fileLock().lockOrFail(); |
399 | } catch print e {
|
400 | if (cic(str(e), "Couldn't aquire lock")) {
|
401 | infoBox("Gazelle is still running, please exit it first!", 10.0);
|
402 | sleepSeconds(10); |
403 | System.exit(1); |
404 | } |
405 | |
406 | } |
407 | concepts.fileLock().deleteOnExit(); |
408 | concepts.persist(); |
409 | |
410 | //db_setMainConcepts(concepts); |
411 | |
412 | //print("Concepts loaded: " + map className(allConcepts(concepts));
|
413 | |
414 | var stems = findConcepts(concepts, Stem); |
415 | print("Stems in DB: " + l(stems));
|
416 | stem = first(stems); |
417 | if (stem == null) {
|
418 | print("Starting new module");
|
419 | makeModule(); |
420 | stem = registerConcept(concepts, new Stem(this, gazelle)); |
421 | } |
422 | gazelle = stem.module; |
423 | |
424 | print(+importedFieldsForMainStem); |
425 | csetAll(stem, importedFieldsForMainStem); |
426 | importedFieldsForMainStem = null; |
427 | |
428 | for (stem : list Stem(concepts)) {
|
429 | stem.host = this; |
430 | stem.startAndShow(); |
431 | } |
432 | |
433 | printWithMS("Dudadoneski");
|
434 | } |
435 | |
436 | void showPrintLog {
|
437 | systemQ.add(-> {
|
438 | var logModule = firstThat(list(concepts, Stem), |
439 | stem -> stem.module instanceof PrintLogModule); |
440 | if (logModule != null) |
441 | logModule.activateWindow(); |
442 | else |
443 | registerConcept(concepts, new Stem(this, new PrintLogModule)).startAndShow(); |
444 | }); |
445 | } |
446 | |
447 | JFrame mainWindow() {
|
448 | ret stem?.window; |
449 | } |
450 | |
451 | O dm_getStem(O moduleOrID) {
|
452 | ret stem; |
453 | } |
454 | |
455 | O resolveModule(O moduleOrID) { ret moduleOrID == stem ? gazelle : moduleOrID; }
|
456 | |
457 | void cleanExit {
|
458 | // e.g. JPaintTool does clean-up when removed (through bindToComponent) |
459 | /*print("Removing all components");
|
460 | for (window : allWindows()) |
461 | setWindowContents(window, jcenteredlabel("Exiting..."));*/
|
462 | |
463 | print("Saving DB for exit");
|
464 | dispose concepts; |
465 | System.exit(0); |
466 | } |
467 | |
468 | File myJar() { ret getBytecodePathForClass(this); }
|
469 | |
470 | AutoCloseable tempDisableCompileButtons() {
|
471 | ret tempDisableButtons(compileButtons()); |
472 | } |
473 | |
474 | void upgradeGazelle {
|
475 | try {
|
476 | printAlsoToSystemOut = true; |
477 | |
478 | // Show an infoBox to make sure the code for infoBox is loaded |
479 | temp tempInfoBox("Updating Gazelle...");
|
480 | |
481 | //temp tempSetBoolVar(compileButtonEnabled, false); |
482 | temp tempDisableCompileButtons(); |
483 | for (f : allJFrames()) setFrameTitle(f, "Updating..."); |
484 | |
485 | File myJar = myJar(); |
486 | print(+myJar); |
487 | |
488 | S existingFilesComp = !incrementalDownloads ? null |
489 | : existingFilesInfo(); |
490 | |
491 | S date = ymdMinusHMS(); |
492 | File f = javaxCodeDir("Downloaded Updates/" + "gazelle-" + date + ".jar");
|
493 | temp progress = tempProgressBar_addToWindowIfPossible(mainWindow(), "Updating Gazelle"); |
494 | |
495 | progress.setText("Downloading Update...");
|
496 | time "Downloading zip" {
|
497 | postBinaryPageToFile(downloadURL(), f, +existingFilesComp); |
498 | } |
499 | printFileInfo(f); |
500 | if (!isNonEmptySingleZip_byMagicHeader(f)) |
501 | ret with infoBox("Bad file downloaded... :(");
|
502 | |
503 | bool replaced; |
504 | if (isFile(myJar)) {
|
505 | // load all my classes to be sure (TODO: could do this in parallel to downloading) |
506 | //print("Loaded " + nClasses(loadAllClassesInByteCodePath(myJar)));
|
507 | |
508 | progress.setText("Replacing with new version: " + renderFileInfo(myJar));
|
509 | File myJarSaved = fileInSubDir("old-code",
|
510 | appendToBaseName(myJar, ".bak." + date)); |
511 | File myJarNew = appendToFileName(myJar, ".new"); |
512 | |
513 | Set<S> toKeep = asSet(tlft(loadTextFileFromZip(f, "to-keep"))); |
514 | if (nempty(toKeep)) {
|
515 | progress.setText("Keeping " + nFiles(toKeep));
|
516 | int have = countFilesInZip(myJar); |
517 | if (l(toKeep) == have && countFilesInZip(f) == 1) {
|
518 | infoBox("Nothing to update - will just restart");
|
519 | deleteFile(myJarNew); |
520 | sleepSeconds(1); |
521 | restart(); |
522 | } |
523 | |
524 | /* |
525 | temp ZipOutputStream out = zipOutputStream(myJar); |
526 | zip2zip_withPredicate(myJarSaved, out, name -> toKeep.contains(name)); |
527 | progress.setText("Adding new files");
|
528 | int n = zip2zip_withPredicate(f, out, name -> !eq(name, "to-keep")); |
529 | progress.setText("Added " + nFiles(n));
|
530 | */ |
531 | |
532 | temp Zip4j_MergeZipFilesWithFilter merger = new(myJarNew); |
533 | merger.addZipFile(myJar, name -> contains(toKeep, name)); |
534 | merger.addZipFile(f, name -> !eq(name, "to-keep")); |
535 | merger.finish(); |
536 | } else |
537 | myJarNew = f; |
538 | |
539 | if (isWindows()) {
|
540 | copyFileVerbose(myJar, myJarSaved); |
541 | copyFileVerbose(myJarNew, myJar); |
542 | deleteFileVerbose_assertSuccess(myJarNew); |
543 | } else {
|
544 | renameFileVerbose_assertSuccess(myJar, myJarSaved); |
545 | renameFileVerbose_assertSuccess(myJarNew, myJar); |
546 | } |
547 | |
548 | printFileInfo(myJar); |
549 | set replaced; |
550 | } |
551 | |
552 | progress.setText("Done");
|
553 | |
554 | if (replaced) |
555 | infoBox("Installed update, replaced " + f2s(myJar) + " - now starting");
|
556 | else |
557 | infoBox("Updated but could not replace originally downloaded jar");
|
558 | |
559 | restart(replaced ? myJar : f); |
560 | } on fail e { printStackTrace(e); }
|
561 | } |
562 | |
563 | void restart(File jar default myJar()) {
|
564 | S javaCmd = or2(currentProcessCommand(), "java"); |
565 | S cmd = pqO(javaCmd) + " -jar " + pqO(jar); |
566 | print(cmd); |
567 | nohup(cmd); |
568 | cleanExit(); |
569 | } |
570 | |
571 | void makeModule() {
|
572 | if (gazelle == null) |
573 | gazelle = callF(moduleMaker); |
574 | } |
575 | |
576 | void reloadModuleInBackground(Stem mod) {
|
577 | restart(); |
578 | } |
579 | |
580 | void initAutoUpdate {
|
581 | print("Making server connection for updates.");
|
582 | serverConnector = snippetUpdateConnector(/*verbose := true*/); |
583 | //serverConnector.verbose = true; |
584 | |
585 | vmBus_onMessage snippetUpdate(voidfunc(L l) {
|
586 | S uri = getString(l, 1); |
587 | new Matches m; |
588 | if (swic(uri, "/transpileOK/", m)) |
589 | if (sameSnippetID(programID(), firstIntAsString(m.rest()))) {
|
590 | if (stem.autoUpdate /*&& autoUpdateDisabled*/) |
591 | upgradeGazelle(); |
592 | //infoBox("Gazelle can be updated!");
|
593 | } |
594 | }); |
595 | |
596 | pcall {
|
597 | computerCount = new ComputerCountListener(serverConnector); |
598 | computerCount.init(); |
599 | } |
600 | } |
601 | |
602 | S downloadURL() {
|
603 | ret "https://botcompany.de/jar/" |
604 | + psI(programID()) + "?withLibs=1&withX30=1" |
605 | + "&mainClassForManifest=Starter" |
606 | + (!downloadJarWithSrc() ? "&noSrc=1" : "") |
607 | + (downloadUncompressedJAR() ? "&uncompressed=1" : ""); |
608 | } |
609 | |
610 | bool downloadJarWithSrc() { false; }
|
611 | bool downloadUncompressedJAR() { false; }
|
612 | |
613 | // called by DynModule |
614 | void revisualizeModule(Stem stem) {
|
615 | stem.revisualize(); |
616 | } |
617 | |
618 | Int computerCount() { ret computerCount == null ? (Int) 0 : computerCount!; }
|
619 | LiveValue<Int> lvComputerCount() { ret computerCount.liveValue(); }
|
620 | |
621 | L<JButton> compileButtons() { ret mapNonNulls(list(Stem), s -> s.compileButton()); }
|
622 | |
623 | // compile main program |
624 | void compile {
|
625 | compile(programID, null); |
626 | } |
627 | |
628 | void compileUtils {
|
629 | compile(utilsSnippetID(), l0 compile); |
630 | } |
631 | |
632 | void compile(S snippetID, Runnable onSuccess) {
|
633 | print("Compiling " + snippetID);
|
634 | |
635 | var gears = resizeImageIcon(imageIcon(#1103061), 16); |
636 | |
637 | temp tempDisableCompileButtons(); |
638 | temp tempSetButtonImages(compileButtons(), gears); |
639 | |
640 | thread { existingFilesInfo(); } // precompute
|
641 | |
642 | transpileOnServerWithErrorWindow(snippetID, true, onSuccess); |
643 | |
644 | print("Done transpilation of " + snippetID);
|
645 | } |
646 | |
647 | public void switchDatabase(File conceptsDir) {
|
648 | printAlsoToSystemOut = true; |
649 | |
650 | temp tempInfoBoxNoHide("Switching database...");
|
651 | |
652 | // copy some things that should really be global |
653 | // like auto-update flag and main window position |
654 | |
655 | importedFieldsForMainStem = cgetAll(stem, stem.fieldsToShareBetweenDatabases()); |
656 | print(+importedFieldsForMainStem); |
657 | |
658 | File newConceptsFile = newFile(conceptsDir, conceptsFileName()); |
659 | if (!fileExists(newConceptsFile)) |
660 | fail(infoBox("Database not found: " + newConceptsFile));
|
661 | |
662 | print("Cleaning up concepts");
|
663 | |
664 | for (Concept c : allConcepts(concepts)) |
665 | cleanUp(c); |
666 | |
667 | print("Releasing DB");
|
668 | gazelle = null; |
669 | dispose concepts; |
670 | |
671 | //print("Safety sleep (1s)");
|
672 | //sleepSeconds(1); |
673 | |
674 | var classFinder = makeClassFinder(); |
675 | |
676 | print("Loading new DB: " + f2s(newConceptsFile));
|
677 | concepts = newConceptsWithClassFinder(newConceptsFile, classFinder); |
678 | startDBAndModules(); |
679 | |
680 | g22utils.openedDB(conceptsDir); |
681 | |
682 | print("Database switch complete, stopping System.out");
|
683 | printAlsoToSystemOut = false; |
684 | } |
685 | |
686 | IF1<S, Class> makeClassFinder() {
|
687 | IF1<S, Class> defaultClassFinder = toIF1(_defaultClassFinder()); |
688 | IF1<S, Class> classFinder = name -> {
|
689 | // class migration |
690 | if (eq(name, "main$G22RecognizerScript")) {
|
691 | S newName = "main$G22Analyzer"; |
692 | print("Migrating legacy class " + name + " to " + newName);
|
693 | name = newName; |
694 | } |
695 | ret defaultClassFinder.get(name); |
696 | }; |
697 | |
698 | // Test classFinder sanity |
699 | |
700 | assertEquals(callF(classFinder, "main$Stem"), Stem.class); |
701 | |
702 | ret classFinder; |
703 | } |
704 | |
705 | transient cached S existingFilesInfo() {
|
706 | L<Map> fingerprints = zipFileToJSONFingerprint_md5(myJar()); |
707 | S s = base64encode(gzipString(jsonEncode(fingerprints))); |
708 | print(existingFilesInfo := nBytes(l(s))); |
709 | ret s; |
710 | } |
711 | } // end of GazelleHost |
Began life as a copy of #1033891
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): bhatertpkbcr, mqqgnosmbjvj
No comments. add comment
| Snippet ID: | #1034637 |
| Snippet name: | GazelleHost + Stem [backup before multiple databases] |
| Eternal ID of this version: | #1034637/1 |
| Text MD5: | 37065f8a6fb74a1468991d51fdaaedf5 |
| Author: | stefan |
| Category: | javax / gazelle v |
| Type: | JavaX (incomplete) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2022-02-25 21:24:49 |
| Source code size: | 20888 bytes / 711 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 378 / 408 |
| Referenced in: | [show references] |