//--------------------------------------------------------------------------- #include #pragma hdrstop #include "MainFrm.h" #include "StatusFrm.h" #include "RemoteMntFrm.h" #include "InfoFrm.h" #include "UnsuFrm.h" #include "cipherfrm.h" #include "UninstallFrm.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" #include #include #include #include #include #include #include #include #include #include #include #include TMainForm *MainForm; int InstallMgrWin::ftpCopy(InstallSource *is, const char *src, const char *dest, bool dirTransfer, const char *suffix) { termed = false; StatusForm->is = is; StatusForm->src = src; StatusForm->dest = dest; StatusForm->suffix = suffix; StatusForm->dirTransfer = dirTransfer; Application->ProcessMessages(); if (StatusForm->ShowModal() == mrCancel) return -1; else return 0; } bool InstallMgrWin::isUserDisclaimerConfirmed() const { static bool confirmed = false; if (!confirmed) { InfoForm->Caption = "W A R N I N G"; InfoForm->info = "\\qc {\\b \\fs20 -=+* WARNING *+=- -=+* WARNING *+=-}\\par\\par\\pard "; InfoForm->info += "Although Install Manager provides a convenient way for installing " "and upgrading SWORD components, it also uses a systematic method " "for accessing sites which gives packet sniffers a target to lock " "into for singling out users." " \\par\\par "; InfoForm->info += "\\qc {\\b \\fs20 " "IF YOU LIVE IN A PERSECUTED COUNTRY AND DO NOT WISH TO RISK DETECTION, " "YOU SHOULD *NOT* USE INSTALL MANAGER'S REMOTE SOURCE FEATURES." "} \\par\\par\\pard "; InfoForm->info += "Also, Remote Sources other than CrossWire may contain less than " "quality modules, modules with unorthodox content, or even modules " "which are not legitimately distributable. Many repositories " "contain wonderfully useful content. These repositories simply " "are not reviewed or maintained by CrossWire and CrossWire " "cannot be held responsible for their content. CAVEAT EMPTOR." " \\par\\par "; InfoForm->info += "{\\b " "If you understand this and are willing to enable remote source features " "then type yes in the box below. " " \\par\\par }"; InfoForm->info += "Enable? [no] "; InfoForm->yesEdit->Visible = true; confirmed = (InfoForm->ShowModal() == mrOk); } return confirmed; } void WinStatusReporter::preStatus(long totalBytes, long completedBytes, const char *message) { StatusForm->totalBytes = totalBytes; StatusForm->completedBytes = completedBytes; StatusForm->buffer = message; StatusForm->PreDownload2(); Application->ProcessMessages(); } void WinStatusReporter::statusUpdate(double dltotal, double dlnow) { if (!dltotal || !StatusForm->totalBytes) return; // prevent division by zero error below int filePercent = (int)((float)(dlnow + 1) / (float)(dltotal) * 100); int totalPercent = (int)((float)(dlnow + StatusForm->completedBytes + 1) / (float)(StatusForm->totalBytes) * 100); StatusForm->statusBar->Caption = ::IntToStr((long)dlnow) + " bytes out of " + ::IntToStr((long)dltotal) + " transferred (file: " + IntToStr(filePercent) + "% / total: " + IntToStr(totalPercent) + "%)"; StatusForm->fileProgress->Position = filePercent; StatusForm->totalProgress->Position = totalPercent; StatusForm->statusBar->Repaint(); Application->ProcessMessages(); } bool InstallMgrWin::getCipherCode(const char *modName, SWConfig *config) { CipherForm->modName = modName; CipherForm->config = config; return (CipherForm->ShowModal() == mrCancel); } __fastcall InstallSourceTab::InstallSourceTab(TComponent *Owner, InstallSource *is) : TControl(Owner) { this->is = is; } __fastcall InstallSourceTab::~InstallSourceTab() { } __fastcall TMainForm::TMainForm(TComponent* Owner) : TForm(Owner) { installCnt = 0; defSelected = false; installTree = new TTntTreeView(this); installTree->Parent = Panel6; installTree->Align = alClient; installTree->Font->Name = "Arial"; localTree = new TTntTreeView(this); localTree->Parent = TabSheet1; localTree->Align = alClient; localTree->OnDblClick = localTreeDblClick; localTree->Font->Name = "Arial"; // migrate really old data if (FileMgr::existsFile("./InstallMgr.conf")) { FileMgr::copyFile("./InstallMgr.conf", "installMgr/InstallMgr.conf"); FileMgr::removeFile("./InstallMgr.conf"); } getDataRootPath(); manager = new SWMgr(); statusReporter = new WinStatusReporter(); installMgr = new InstallMgrWin((getDataRootPath()+"installMgr").c_str(), statusReporter); localMgr = 0; } SWBuf TMainForm::getDataRootPath(bool forceRefresh) { static SWBuf dataRootPath = ""; if (!dataRootPath.length() || forceRefresh) { SWMgr *letMgrTry = new SWMgr(); if (!letMgrTry->config) { SWBuf envallusersdir = getenv("ALLUSERSPROFILE"); if (envallusersdir.length()) { dataRootPath = envallusersdir; if ((!dataRootPath.endsWith("\\")) && (!dataRootPath.endsWith("/"))) dataRootPath += "/"; dataRootPath += "Application Data/sword"; } else { dataRootPath = "./"; } dataRootPath.replaceBytes("\\", '/'); // if our mgr couldn't find modules, then we probably need // to initialize. Let's initialize! SWBuf path = dataRootPath + "mods.d/globals.conf"; int fd = FileMgr::createPathAndFile(path); SWBuf globals = "[Globals]\nAutoInstall=./newmods/\n"; write(fd, globals.c_str(), globals.size()); close(fd); } else { dataRootPath = letMgrTry->prefixPath; } delete letMgrTry; // Let's be sure our app-specific folder exists if (!FileMgr::existsDir(dataRootPath+"/BibleCS")) FileMgr::createParent(dataRootPath+"/BibleCS/layout.conf"); } return dataRootPath; } __fastcall TMainForm::~TMainForm() { } void __fastcall TMainForm::FormCreate(TObject *Sender) { refreshPageControl(); SWLog::setSystemLog(new SWWinLog(this->Handle)); // set the system logger to our MSWindows specific SWLog class fillInstallTree(); fillSourceTree(localTree); } void TMainForm::refreshPageControl() { InstallSourceMap::iterator source; while (PageControl1->PageCount > 1) { delete PageControl1->Pages[1]; } for (source = installMgr->sources.begin(); source != installMgr->sources.end(); source++) { InstallSourceTab *ist = new InstallSourceTab(this, source->second); source->second->userData = (void *)ist; addSource(ist); } } void TMainForm::addSource(InstallSourceTab *ist) { TTabSheet *newtab = new TTabSheet(this); TTntTreeView *newtree = new TTntTreeView(this); TSpeedButton *newbutton = new TSpeedButton(this); TPanel *newpanel = new TPanel(this); char buf[512]; SectionMap::iterator sit; newtab->Caption = ist->is->caption.c_str(); newtab->Hint = ist->is->source.c_str(); newtab->ShowHint = true; newtab->PageControl = PageControl1; ist->Parent = newtab; ist->tree = newtree; newpanel->Parent = newtab; newpanel->Align = alTop; newpanel->BevelOuter = bvNone; newpanel->BevelInner = bvNone; newpanel->Height = 25; newbutton->Parent = newpanel; newbutton->Caption = "Refresh from Remote Source"; newbutton->Width = 210; newbutton->OnClick = RefreshRemoteSource; newbutton->Flat = true; newbutton->Glyph = SpeedButton2->Glyph; newtree->Parent = newtab; newtree->Align = alClient; newtree->ReadOnly = true; newtree->OnDblClick = localTreeDblClick; newtree->Images = ImageList1; newtree->StateImages = ImageList2; newtree->Font->Name = "Arial"; fillSourceTree(newtree, ist->is); } const char *TMainForm::getLocalDir() { ConfigEntMap::iterator entry; entry = installMgr->installConf->Sections["Sources"].find("LocalPath"); if (entry == installMgr->installConf->Sections["Sources"].end()) { installMgr->installConf->Sections["Sources"].insert(ConfigEntMap::value_type("LocalPath", "d:/sword")); entry = installMgr->installConf->Sections["Sources"].find("LocalPath"); } return entry->second.c_str(); } void TMainForm::setLocalDir(const char *idir) { (*(installMgr->installConf))["Sources"]["LocalPath"] = idir; } //--------------------------------------------------------------------------- void __fastcall TMainForm::LocalPath1Click(TObject *Sender) { AnsiString Dir = getLocalDir(); // if (SelectDirectory(Dir, TSelectDirOpts(), 0)) { if (SelectDirectory("Select Local Path", WideString(""), Dir)) { setLocalDir(Dir.c_str()); installMgr->installConf->Save(); fillSourceTree(localTree); if (defSelected) MessageBox(this->Handle, "Since no books are yet installed, a basic set has been selected as a suggested starting point. Please review and tailor to your liking.", "Default Module Set Selected", MB_OK); } } //--------------------------------------------------------------------------- void TMainForm::fillInstallTree() { ModMap::iterator mods; TTntTreeNode *node; SWBuf nodeName; installTree->Items->Clear(); if (!manager->configPath) return; installCnt = 0; for (mods = manager->Modules.begin(); mods != manager->Modules.end(); mods++) { for (node = installTree->Items->GetFirstNode(); node; node = node->getNextSibling()) { if (!strcmp(WideStringToUTF8(node->Text).c_str(), mods->second->getType())) { break; } } if (!node) { // Add Section if (!strncmp(mods->second->getType(), "Bibl", 4)) // If Bibles, put first in list node = installTree->Items->AddChildFirst(0, mods->second->getType()); else node = installTree->Items->AddChild(0, mods->second->getType()); } nodeName = "["; nodeName += mods->second->getName(); nodeName += "] "; nodeName += mods->second->getDescription(); node = installTree->Items->AddChildObject(node, UTF8ToWideString(nodeName.c_str()), (void *)mods->second->getName()); installCnt++; } for (node = installTree->Items->GetFirstNode(); node; node = node->getNextSibling()) node->Expand(true); node = installTree->Items->GetFirstNode(); if (node) node->MakeVisible(); } void TMainForm::fillSourceTree(TTntTreeView *tree, InstallSource *is) { ModMap::iterator mods; TTntTreeNode *node; SectionMap::iterator sections, targetSection; ConfigEntMap::iterator entry; SWBuf secName; const char *modDesc; SWBuf nodeName; SWBuf targetVersion; SWBuf sourceVersion; SWBuf softwareVersion; bool cipher; bool showLocked = LockedModules1->Checked; SWMgr *mgr; if (tree == localTree) { if (localMgr) delete localMgr; mgr = localMgr = new SWMgr(getLocalDir()); } else { InstallSourceTab *ist = (InstallSourceTab *) tree->Parent->Controls[0]; mgr = ist->is->getMgr(); } tree->Items->Clear(); if (!mgr->configPath) return; for (sections = mgr->config->Sections.begin(); sections != mgr->config->Sections.end(); sections++) { cipher = false; if (!strcmp(sections->first.c_str(), "Globals")) // skip [Globals] continue; entry = sections->second.find("CipherKey"); if (entry != sections->second.end()) { if (showLocked) cipher = true; else continue; } mods = mgr->Modules.find(sections->first.c_str()); if (mods != mgr->Modules.end()) secName = mods->second->getType(); else { secName = "Other"; } SWBuf misc1 = ((entry = sections->second.find("Category")) != sections->second.end()) ? (SWBuf)(*entry).second.c_str() : (SWBuf)""; if (misc1.length() > 0) secName = misc1; entry = sections->second.find("Description"); if (entry != sections->second.end()) modDesc = entry->second.c_str(); else modDesc = ""; targetVersion = "0.0"; sourceVersion = "1.0"; softwareVersion = (const char *)SWVersion::currentVersion; entry = sections->second.find("Version"); if (entry != sections->second.end()) sourceVersion = entry->second.c_str(); entry = sections->second.find("MinimumVersion"); if (entry != sections->second.end()) softwareVersion = entry->second.c_str(); targetSection = manager->config->Sections.find(sections->first); if (targetSection != manager->config->Sections.end()) { targetVersion = "1.0"; entry = targetSection->second.find("Version"); if (entry != targetSection->second.end()) targetVersion = entry->second; } if (SWVersion(sourceVersion.c_str()) > SWVersion(targetVersion.c_str())) { for (node = tree->Items->GetFirstNode(); node; node = node->getNextSibling()) { if (!strcmp(WideStringToUTF8(node->Text).c_str(), secName.c_str())) { break; } } if (!node) { // Add Section if (!strncmp(secName.c_str(), "Bibl", 4)) // If Bibles, put first in list node = tree->Items->AddChildFirst(0, UTF8ToWideString(secName.c_str())); else node = tree->Items->AddChild(0, UTF8ToWideString(secName.c_str())); node->ImageIndex = 0; } nodeName = (SWBuf)"[" + sections->first + "] " + modDesc; node = tree->Items->AddChildObject(node, UTF8ToWideString(nodeName.c_str()), (void *) sections->first.c_str()); if (SWVersion(targetVersion.c_str()) < SWVersion("1.0")) { node->ImageIndex = 1; node->SelectedIndex = 1; } else { node->ImageIndex = 2; node->SelectedIndex = 2; } if (cipher) { node->ImageIndex += 2; node->SelectedIndex += 2; } if (SWVersion::currentVersion < SWVersion(softwareVersion.c_str())) { node->ImageIndex = 5; node->SelectedIndex = 5; } if (!installCnt) { node->StateIndex = installMgr->isDefaultModule(sections->first.c_str()); if (!defSelected) defSelected = node->StateIndex; } else node->StateIndex = 0; } } for (node = tree->Items->GetFirstNode(); node; node = node->getNextSibling()) node->Expand(true); node = tree->Items->GetFirstNode(); if (node) node->MakeVisible(); } void __fastcall TMainForm::Button5Click(TObject *Sender) { TTntTreeView *tree; for (int i = 0; i < PageControl1->ActivePage->ControlCount; i++) { if (PageControl1->ActivePage->Controls[i]->ClassNameIs("TTntTreeView")) { tree = (TTntTreeView *)(PageControl1->ActivePage->Controls[i]); break; } } TTntTreeNode *node = tree->Selected; if (node) { if (node->Parent) { if (node->ImageIndex == 5) { SWMgr *mgr = (tree == localTree) ? manager : ((InstallSourceTab *) PageControl1->ActivePage->Controls[0])->is->getMgr(); SWBuf minVer = (*mgr->config)[(const char *)node->Data]["MinimumVersion"]; UnsuForm->Caption = "Need To Upgrade"; UnsuForm->info = "\\qc {\\b \\fs20 Newer Software Version Required.}\\par\\par\\pard "; UnsuForm->info += "This module requires a newer version of the SWORD software engine. \\par\\par "; UnsuForm->info += "Your Current Version: "; UnsuForm->info += (const char *)SWVersion::currentVersion; UnsuForm->info += "\\par Required Version: "; UnsuForm->info += minVer.c_str(); UnsuForm->info += "\\par\\par\\b\\qc Please visit http://www.crosswire.org to upgrade."; if (UnsuForm->ShowModal() == mrOk) { return; } } if (node->StateIndex == 1) node->StateIndex = 0; //node->StateIndex; else node->StateIndex = 1; tree->Repaint(); } } } //--------------------------------------------------------------------------- void __fastcall TMainForm::localTreeDblClick(TObject *Sender) { Button5Click(Sender); } //--------------------------------------------------------------------------- int TMainForm::selectAll(TTntTreeView *tree, bool sel) { TTntTreeNode *node; TTntTreeNode *node2; int retCount = 0; for (node = tree->Items->GetFirstNode(); node; node = node->getNextSibling()) { for (node2 = node->getFirstChild(); node2; node2 = node2->getNextSibling()) { if (node2->ImageIndex != 5) { if (node2->StateIndex == 1) { if (!sel) { node2->StateIndex = 0; //node2->StateIndex; retCount++; } } else { if (sel) { node2->StateIndex = 1; retCount++; } } } } } return retCount; } // SELECT ALL void __fastcall TMainForm::Button6Click(TObject *Sender) { TTntTreeView *tree; for (int i = 0; i < PageControl1->ActivePage->ControlCount; i++) { if (PageControl1->ActivePage->Controls[i]->ClassNameIs("TTntTreeView")) { tree = (TTntTreeView*)(PageControl1->ActivePage->Controls[i]); break; } } if (!selectAll(tree, true)) selectAll(tree, false); tree->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TMainForm::Image1Click(TObject *Sender) { ShellExecute(this->Handle, "open", "http://www.crosswire.org", NULL, NULL, SW_SHOWNORMAL); } //--------------------------------------------------------------------------- void TMainForm::fillAllSourceTrees() { fillSourceTree(localTree); for (int i = 1; i < PageControl1->PageCount; i++) { InstallSourceTab *ist = (InstallSourceTab *) MainForm->PageControl1->Pages[i]->Controls[0]; fillSourceTree(ist->tree, ist->is); } } // REMOVE MODULE void __fastcall TMainForm::Button4Click(TObject *Sender) { TTntTreeNode *node = installTree->Selected; if (node) { if (node->Parent) { installMgr->removeModule(manager, (const char *)node->Data); delete manager; manager = new SWMgr(); fillInstallTree(); fillAllSourceTrees(); } } } //--------------------------------------------------------------------------- // INSTALL void __fastcall TMainForm::Button2Click(TObject *Sender) { TTntTreeNode *node; int count = 0; int abort = 0; class TWaitCursor { public: TWaitCursor() : oldc(Screen->Cursor) { Screen->Cursor = crHourGlass; } ~TWaitCursor() { Screen->Cursor = oldc; } private: TCursor oldc; } wait; // show hourglass TTntTreeView *tree; for (int i = 0; i < PageControl1->ActivePage->ControlCount; i++) { if (PageControl1->ActivePage->Controls[i]->ClassNameIs("TTntTreeView")) { tree = (TTntTreeView *)(PageControl1->ActivePage->Controls[i]); break; } } for (node = tree->Items->GetFirstNode(); node; node = node->GetNext()) { if (node->StateIndex == 1) count++; } // do true progress bar if (!count) { MessageBox(this->WindowHandle, "Please first choose which modules you would like to install by double-clicking a module in the 'Available' tree.", "Please select modules first.", MB_OK); return; // if nothing is selected, do nothing } progressBar->Max = count; progressBar->Position = 0; for (node = tree->Items->GetFirstNode(); node; node = node->GetNext()) { if (node->StateIndex == 1) { // if selected for install CipherForm->cipherEdit->Text = ""; if ((node->ImageIndex == 2) || (node->ImageIndex == 4)) { // if this is an upgrade installMgr->removeModule(manager, (const char *)node->Data); } // install module statusBar->Caption = "Installing: " + node->Text + "..."; statusBar->Repaint(); if (tree == localTree) abort = installMgr->installModule(manager, getLocalDir(), (const char *)node->Data, 0); else abort = installMgr->installModule(manager, 0, (const char *)node->Data, ((InstallSourceTab *) PageControl1->ActivePage->Controls[0])->is); if (abort) break; progressBar->Position++; } } delete manager; manager = new SWMgr(); fillInstallTree(); fillAllSourceTrees(); statusBar->Caption = ""; progressBar->Position = 0; } void __fastcall TMainForm::RefreshRemoteSource(TObject *Sender) { InstallSourceTab *ist = (InstallSourceTab *) MainForm->PageControl1->ActivePage->Controls[0]; installMgr->refreshRemoteSource(ist->is); fillSourceTree(ist->tree, ist->is); if (defSelected) MessageBox(this->Handle, "Since no books are yet installed, a basic set has been selected as a suggested starting point. Please review and tailor to your liking.", "Default Module Set Selected", MB_OK); } void __fastcall TMainForm::SpeedButton1Click(TObject *Sender) { if (installMgr->isUserDisclaimerConfirmed()) { RemoteMntForm->ShowModal(); delete installMgr; installMgr = new InstallMgrWin((getDataRootPath()+"installMgr").c_str(), statusReporter); refreshPageControl(); } } void __fastcall TMainForm::SpeedButton5Click(TObject *Sender) { TTntTreeView *tree; InstallSourceTab *ist = 0; SectionMap::iterator module; ConfigEntMap::iterator entry, entryEnd; if (PageControl1->ActivePage != PageControl1->Pages[0]) { ist = (InstallSourceTab *) PageControl1->ActivePage->Controls[0]; tree = ist->tree; } else tree = localTree; TTntTreeNode *node = tree->Selected; if (node) { if (node->Parent) { SWMgr *mgr = (ist) ? ist->is->getMgr() : new SWMgr(getLocalDir()); module = mgr->config->Sections.find((const char *)node->Data); if (module != mgr->config->Sections.end()) { SWBuf targetVersion = "0.0"; SWBuf sourceVersion = "1.0"; SectionMap::iterator targetSection; entry = module->second.find("Version"); if (entry != module->second.end()) sourceVersion = entry->second.c_str(); targetSection = manager->config->Sections.find(module->first); if (targetSection != manager->config->Sections.end()) { targetVersion = "1.0"; entry = targetSection->second.find("Version"); if (entry != targetSection->second.end()) targetVersion = entry->second; } bool showAllChanges = false; if (SWVersion(targetVersion.c_str()) < SWVersion("1.0")) { InfoForm->info = (SWBuf)"\\pard{\\b * Module Available for Install: \\tab " + sourceVersion + " } \\par "; showAllChanges = true; } else { InfoForm->info = (SWBuf)"\\pard{\\b + Module Available for Update.}\\par\\tab Current Version: \\tab " + targetVersion + " \\par\\tab Upgrade Version:\\tab " + sourceVersion + " \\par "; } InfoForm->info += " \\par \\par \\pard "; bool headingPrinted = false; for (entry = module->second.begin(); entry != module->second.end(); entry++) { if (!strncmp(entry->first.c_str(), "History_", 8)) { if (showAllChanges || SWVersion(&entry->first.c_str()[8]) > SWVersion(targetVersion.c_str())) { if (!headingPrinted) { headingPrinted = true; if (showAllChanges) InfoForm->info += "\\par{\\b History: }\\par "; else InfoForm->info += "\\par{\\b Changes: }\\par "; } InfoForm->info += "\\tab "; InfoForm->info += (SWBuf)(entry->first.c_str()+8) + " \\tab "+ entry->second.c_str(); InfoForm->info += "\\par "; } } } entry = module->second.find("About"); if (entry != module->second.end()) { InfoForm->info += "\\par{\\b About: } \\par\\par "; InfoForm->info += entry->second.c_str(); } InfoForm->Caption = "Module Information"; InfoForm->yesEdit->Visible = false; InfoForm->ShowModal(); } if (!ist) delete mgr; } } } //--------------------------------------------------------------------------- void __fastcall TMainForm::Exit1Click(TObject *Sender) { Close(); } //--------------------------------------------------------------------------- void TMainForm::deleteAllModules() { SWMgr *mgr = new SWMgr(); int count = mgr->Modules.size(); if (!count) return; UninstallForm->Show(); UninstallForm->ProgressBar1->Max = count; UninstallForm->ProgressBar1->Position = 0; ModMap::iterator it; for (it = mgr->Modules.begin(); it != mgr->Modules.end(); it = mgr->Modules.begin()) { SWBuf label = "Uninstalling: ["; label += it->second->getName(); label += "] "; label += it->second->getDescription(); UninstallForm->Label1->Caption = UTF8ToWideString(label.c_str()); UninstallForm->Label1->Repaint(); installMgr->removeModule(mgr, it->second->getName()); UninstallForm->ProgressBar1->Position = UninstallForm->ProgressBar1->Position + 1; UninstallForm->ProgressBar1->Repaint(); } delete mgr; UninstallForm->Hide(); return; } void __fastcall TMainForm::FormShow(TObject *Sender) { for (int i=0;i<=ParamCount();i++) { if (LowerCase(ParamStr(i)) == "-uninstall") { if (IDYES == MessageBox(this->Handle, "Would you like to remove all SWORD modules?", "Delete All Modules", MB_YESNO)) deleteAllModules(); Application->Terminate(); } if (LowerCase(ParamStr(i)) == "-init") { if (i installConf->Save(); Application->Terminate(); } } } if (defSelected) MessageBox(this->Handle, "Since no books are yet installed, a basic set has been selected as a suggested starting point. Please review and tailor to your liking.", "Default Module Set Selected", MB_OK); } //--------------------------------------------------------------------------- void __fastcall TMainForm::LockedModules1Click(TObject *Sender) { LockedModules1->Checked = !(LockedModules1->Checked); if (LockedModules1->Checked) { InfoForm->Caption = "About Locked Modules"; InfoForm->info = "\\qc {\\b \\fs20 About Locked Modules}\\par\\par\\pard "; InfoForm->info += "The modules you are about to enable are copyrighted and will require an unlock key to use. \\par\\par\\pard "; InfoForm->info += "CrossWire does not publicly distribute unlock keys for any module. You will need to obtain these keys directly from publisher of the module.\\par\\par\\pard "; InfoForm->info += "\t-CrossWire Bible Society. "; InfoForm->yesEdit->Visible = false; InfoForm->ShowModal(); } fillAllSourceTrees(); } //--------------------------------------------------------------------------- void __fastcall TMainForm::Contents1Click(TObject *Sender) { SWConfig optionsconf("options.conf"); SWBuf helpDir; ConfigEntMap::iterator it = optionsconf.Sections["Help"].find("Directory"); if (it != optionsconf.Sections["Help"].end()) helpDir = (*it).second; else helpDir = ".\\help"; SWBuf helpExe = helpDir + "\\Sword.chm::modulesh.html#instmgr"; ShellExecute(this->Handle, "open", "hh", helpExe.c_str(), NULL, SW_SHOWNORMAL); } //--------------------------------------------------------------------------- void __fastcall TMainForm::FormClose(TObject *Sender, TCloseAction &Action) { delete manager; if (localMgr) delete localMgr; delete installMgr; } //--------------------------------------------------------------------------- void __fastcall TMainForm::BuildPortableApp1Click(TObject *Sender) { if (getDataRootPath() != "./") { // migrate old data if (FileMgr::existsDir(getDataRootPath()+"mods.d")) { FileMgr::copyDir(getDataRootPath()+"mods.d", "./mods.d"); } if (FileMgr::existsDir(getDataRootPath()+"modules")) { FileMgr::copyDir(getDataRootPath()+"modules", "./modules"); } SWBuf path = getDataRootPath(); path.replaceBytes("\\", '/'); InfoForm->info = (SWBuf)"Library has been copied locally from: " + path + "\\par\\par\\pard "; InfoForm->info += "You may now copy your SWORD program folder to a USB stick or other portable media to use as a self-contained portable app."; delete manager; manager = new SWMgr(); getDataRootPath(true); delete installMgr; installMgr = new InstallMgrWin((getDataRootPath()+"installMgr").c_str(), statusReporter); fillInstallTree(); refreshPageControl(); } else { InfoForm->info = (SWBuf)"Library is already local at: " + getDataRootPath(); } InfoForm->Caption = "Build Portable App"; InfoForm->yesEdit->Visible = false; InfoForm->ShowModal(); } //--------------------------------------------------------------------------- void __fastcall TMainForm::MigrateBookLibraryPubliclytoLocalMachine1Click( TObject *Sender) { SWBuf dataRootPath = getDataRootPath(); if (dataRootPath == "./") { SWBuf envallusersdir = getenv("ALLUSERSPROFILE"); if (envallusersdir.length()) { delete manager; delete installMgr; dataRootPath = envallusersdir; if ((!dataRootPath.endsWith("\\")) && (!dataRootPath.endsWith("/"))) dataRootPath += "/"; dataRootPath += "Application Data/sword"; if (!FileMgr::existsDir(dataRootPath)) FileMgr::createParent(dataRootPath+"/mods.d/globals.conf"); // migrate old data if (FileMgr::existsDir("./mods.d")) { FileMgr::copyDir("./mods.d", dataRootPath+"/mods.d"); FileMgr::removeDir("./mods.d"); // odd "ReadOnly" flag is set and SWORD's ::remove can't actually remove without "Permission Denied" error RemoveDirectory("./mods.d"); } if (FileMgr::existsDir("./modules")) { FileMgr::copyDir("./modules", dataRootPath+"/modules"); FileMgr::removeDir("./modules"); // this still doesn't work because subdirs exist, but mods.d is the important one. RemoveDirectory("./modules"); } // BibleCS Specific Stuff if (FileMgr::existsDir("./bookmarks")) { FileMgr::copyDir("./bookmarks", dataRootPath+"/bookmarks"); FileMgr::removeDir("./bookmarks"); RemoveDirectory("./bookmarks"); } if (FileMgr::existsDir("./BibleCS")) { FileMgr::copyDir("./BibleCS", dataRootPath+"/BibleCS"); FileMgr::removeDir("./BibleCS"); RemoveDirectory("./BibleCS"); } if (FileMgr::existsFile("./options.conf")) { FileMgr::copyFile("./options.conf", dataRootPath+"/BibleCS/options.conf"); FileMgr::removeFile("./options.conf"); } if (FileMgr::existsFile("./layout.conf")) { FileMgr::copyFile("./layout.conf", dataRootPath+"/BibleCS/layout.conf"); FileMgr::removeFile("./layout.conf"); } if (FileMgr::existsFile("./userprefs.conf")) { FileMgr::copyFile("./userprefs.conf", dataRootPath+"/BibleCS/userprefs.conf"); FileMgr::removeFile("./userprefs.conf"); } // -------------------------- manager = new SWMgr(); dataRootPath = getDataRootPath(true); installMgr = new InstallMgrWin((dataRootPath+"installMgr").c_str(), statusReporter); fillInstallTree(); refreshPageControl(); } SWBuf path = getDataRootPath(); path.replaceBytes("\\", '/'); InfoForm->info = (SWBuf)"Library has been migrated to: " + path + "\\par\\par\\pard"; InfoForm->info += "You may now use other SWORD programs with this library"; } else { SWBuf path = getDataRootPath(); path.replaceBytes("\\", '/'); InfoForm->info = (SWBuf)"Library is already public at: " + path; } InfoForm->Caption = "Migrate SWORD Library to Public Area"; InfoForm->yesEdit->Visible = false; InfoForm->ShowModal(); } //---------------------------------------------------------------------------