DWORD WINAPI InstallerThread(LPVOID data) { gGlobalData.success = false; if (!CreateInstallationDirectory()) goto Error; ProgressStep(); if (!InstallCopyFiles()) goto Error; if (gGlobalData.registerAsDefault) { // need to sublaunch SumatraPDF.exe instead of replicating the code // because registration uses translated strings ScopedMem<WCHAR> installedExePath(GetInstalledExePath()); CreateProcessHelper(installedExePath, L"-register-for-pdf"); } if (gGlobalData.installBrowserPlugin) InstallBrowserPlugin(); else if (IsBrowserPluginInstalled()) UninstallBrowserPlugin(); if (gGlobalData.installPdfFilter) InstallPdfFilter(); else if (IsPdfFilterInstalled()) UninstallPdfFilter(); if (gGlobalData.installPdfPreviewer) InstallPdfPreviewer(); else if (IsPdfPreviewerInstalled()) UninstallPdfPreviewer(); if (!CreateAppShortcut(true) && !CreateAppShortcut(false)) { NotifyFailed(_TR("Failed to create a shortcut")); goto Error; } // consider installation a success from here on // (still warn, if we've failed to create the uninstaller, though) gGlobalData.success = true; if (!WriteUninstallerRegistryInfo(HKEY_LOCAL_MACHINE) && !WriteUninstallerRegistryInfo(HKEY_CURRENT_USER)) { NotifyFailed(_TR("Failed to write the uninstallation information to the registry")); } if (!WriteExtendedFileExtensionInfo(HKEY_LOCAL_MACHINE) && !WriteExtendedFileExtensionInfo(HKEY_CURRENT_USER)) { NotifyFailed(_TR("Failed to write the extended file extension information to the registry")); } ProgressStep(); Error: // TODO: roll back installation on failure (restore previous installation!) if (gHwndFrame && !gGlobalData.silent) { Sleep(500); // allow a glimpse of the completed progress bar before hiding it PostMessage(gHwndFrame, WM_APP_INSTALLATION_FINISHED, 0, 0); } return 0; }
static bool ExtractFiles(lzma::SimpleArchive *archive) { lzma::FileInfo *fi; char *uncompressed; FileTransaction trans; for (int i = 0; gPayloadData[i].fileName; i++) { if (!gPayloadData[i].install) continue; int idx = lzma::GetIdxFromName(archive, gPayloadData[i].fileName); if (-1 == idx) { NotifyFailed(_TR("Some files to be installed are damaged or missing")); return false; } fi = &archive->files[idx]; uncompressed = lzma::GetFileDataByIdx(archive, idx, nullptr); if (!uncompressed) { NotifyFailed(_TR("The installer has been corrupted. Please download it again.\nSorry for the inconvenience!")); return false; } ScopedMem<WCHAR> filePath(str::conv::FromUtf8(fi->name)); ScopedMem<WCHAR> extPath(path::Join(gGlobalData.installDir, filePath)); bool ok = trans.WriteAll(extPath, uncompressed, fi->uncompressedSize); free(uncompressed); if (!ok) { ScopedMem<WCHAR> msg(str::Format(_TR("Couldn't write %s to disk"), filePath)); NotifyFailed(msg); return false; } trans.SetModificationTime(extPath, fi->ftModified); ProgressStep(); } return trans.Commit(); }
static bool InstallCopyFiles() { // extract all payload files one by one (transacted, if possible) ZipFile archive(GetOwnPath()); FileTransaction trans; for (int i = 0; gPayloadData[i].filepath; i++) { // skip files that are only uninstalled if (!gPayloadData[i].install) continue; ScopedMem<WCHAR> filepathT(str::conv::FromUtf8(gPayloadData[i].filepath)); size_t size; ScopedMem<char> data(archive.GetFileData(filepathT, &size)); if (!data) { NotifyFailed(L"Some files to be installed are damaged or missing"); return false; } ScopedMem<WCHAR> extpath(path::Join(gGlobalData.installDir, path::GetBaseName(filepathT))); bool ok = trans.WriteAll(extpath, data, size); if (!ok) { ScopedMem<WCHAR> msg(str::Format(L"Couldn't write %s to disk", filepathT)); NotifyFailed(msg); return false; } // set modification time to original value FILETIME ftModified = archive.GetFileTime(filepathT); trans.SetModificationTime(extpath, ftModified); ProgressStep(); } return trans.Commit(); }
int main(int argc, char *argv[]) { MyCmdLine(argc, argv); if (argc < 2) { Usage(); return 0; } if (opt_version) { printf("uchime v" MY_VERSION ".%s\n", SVN_VERSION); return 0; } printf("uchime v" MY_VERSION ".%s\n", SVN_VERSION); printf("by Robert C. Edgar\n"); printf("http://drive5.com/uchime\n"); printf("This code is donated to the public domain.\n"); printf("\n"); if (!optset_w) opt_w = 8; float MinFractId = 0.95f; if (optset_id) MinFractId = (float) opt_id; Log("%8.2f minh\n", opt_minh); Log("%8.2f xn\n", opt_xn); Log("%8.2f dn\n", opt_dn); Log("%8.2f xa\n", opt_xa); Log("%8.2f mindiv\n", opt_mindiv); Log("%8u maxp\n", opt_maxp); if (opt_input == "" && opt_uchime != "") opt_input = opt_uchime; if (opt_input == "") Die("Missing --input"); g_UchimeDeNovo = (opt_db == ""); if (opt_uchimeout != "") g_fUChime = CreateStdioFile(opt_uchimeout); if (opt_uchimealns != "") g_fUChimeAlns = CreateStdioFile(opt_uchimealns); SeqDB Input; SeqDB DB; Input.FromFasta(opt_input); if (!Input.IsNucleo()) Die("Input contains amino acid sequences"); const unsigned QuerySeqCount = Input.GetSeqCount(); vector<unsigned> Order; for (unsigned i = 0; i < QuerySeqCount; ++i) Order.push_back(i); if (g_UchimeDeNovo) { vector<float> Abs; for (unsigned i = 0; i < QuerySeqCount; ++i) { const char *Label = Input.GetLabel(i); float Ab = GetAbFromLabel(Label); Abs.push_back(Ab); } SortDescending(Abs, Order); DB.m_IsNucleoSet = true; DB.m_IsNucleo = true; } else { DB.FromFasta(opt_db); if (!DB.IsNucleo()) Die("Database contains amino acid sequences"); } vector<ChimeHit2> Hits; unsigned HitCount = 0; for (unsigned i = 0; i < QuerySeqCount; ++i) { unsigned QuerySeqIndex = Order[i]; SeqData QSD; Input.GetSeqData(QuerySeqIndex, QSD); float QAb = -1.0; if (g_UchimeDeNovo) QAb = GetAbFromLabel(QSD.Label); ChimeHit2 Hit; AlnParams &AP = *(AlnParams *) 0; AlnHeuristics &AH = *(AlnHeuristics *) 0; HSPFinder &HF = *(HSPFinder *) 0; bool Found = SearchChime(DB, QSD, QAb, AP, AH, HF, MinFractId, Hit); if (Found) ++HitCount; else { if (g_UchimeDeNovo) DB.AddSeq(QSD.Label, QSD.Seq, QSD.L); } WriteChimeHit(g_fUChime, Hit); ProgressStep(i, QuerySeqCount, "%u/%u chimeras found (%.1f%%)", HitCount, i, Pct(HitCount, i+1)); } Log("\n"); Log("%s: %u/%u chimeras found (%.1f%%)\n", opt_input.c_str(), HitCount, QuerySeqCount, Pct(HitCount, QuerySeqCount)); CloseStdioFile(g_fUChime); CloseStdioFile(g_fUChimeAlns); ProgressExit(); return 0; }
static bool InstallCopyFiles() { FileInfo fileInfos[32]; HRSRC resSrc = FindResource(ghinst, MAKEINTRESOURCE(1), RT_RCDATA); CrashIf(!resSrc); HGLOBAL res = LoadResource(NULL, resSrc); CrashIf(!res); const uint8_t *data = (const uint8_t*)LockResource(res); DWORD dataSize = SizeofResource(NULL, resSrc); // extract all payload files one by one (transacted, if possible) FileTransaction trans; const int32_t *idata = (const int32_t*)data; int32_t fileCount = *idata++; CrashIf(fileCount >= dimof(fileInfos)); int32_t off = 0; for (int32_t i = 0; i < fileCount; i++) { fileInfos[i].off = off; fileInfos[i].sizeUncompressed = *idata++; fileInfos[i].sizeCompressed = *idata++; off += fileInfos[i].sizeCompressed; data = (const uint8_t*)idata; fileInfos[i].name = (const char*)data; while (*data) { ++data; } ++data; idata = (const int32_t*)data; } uint8_t *dst; for (int32_t i = 0; i < fileCount; i++) { ScopedMem<WCHAR> filepathT(str::conv::FromUtf8(fileInfos[i].name)); int32_t srcLen = fileInfos[i].sizeCompressed; off = fileInfos[i].off; const uint8_t *src = data + off; unsigned dstLen; dst = decodeLZMA((uint8_t*)src, (unsigned)srcLen, &dstLen); CrashIf(dstLen != (unsigned)fileInfos[i].sizeUncompressed); ScopedMem<WCHAR> extpath(path::Join(gGlobalData.installDir, path::GetBaseName(filepathT))); bool ok = trans.WriteAll(extpath, dst, dstLen); if (!ok) { ScopedMem<WCHAR> msg(str::Format(_TR("Couldn't write %s to disk"), filepathT)); NotifyFailed(msg); goto Error; } free(dst); // set modification time to original value //FILETIME ftModified = archive.GetFileTime(filepathT); //trans.SetModificationTime(extpath, ftModified); ProgressStep(); } UnlockResource(res); return trans.Commit(); Error: UnlockResource(res); return false; }
//////////////////////////////////////////////////////////////////////////////// // Предварительная обработка // (07.07.2000) Изначально взято из puma.dll без изменений // сильно привязана к пуме // в начале окучиваем выделение компонент Bool32 PreProcessImage( PRSPreProcessImage Image ) { Bool32 gbAutoRotate = Image->gbAutoRotate; puchar *gpRecogDIB = Image->pgpRecogDIB; Handle hCPAGE = Image->hCPAGE; const char * glpRecogName = *Image->pglpRecogName; PCIMAGEBITMAPINFOHEADER info = (PCIMAGEBITMAPINFOHEADER)Image->pinfo; ///////////////////////////////// Bool32 rc = TRUE; //char * lpRecogName = NULL; uint32_t Angle = 0; hWndTurn = 0; if(InitPRGTIME()) ProgressStart(); if(!ProgressStep(1,5)) rc = FALSE; // Andrey 12.11.01 // Проинициализируем контейнер CPAGE // if(rc) { PAGEINFO PInfo = {0}; GetPageInfo(hCPAGE,&PInfo); strcpy((char*)PInfo.szImageName, glpRecogName); PInfo.BitPerPixel = info->biBitCount; PInfo.DPIX = info->biXPelsPerMeter*254L/10000; // PInfo.DPIX = PInfo.DPIX < 200 ? 200 : PInfo.DPIX; PInfo.DPIY = info->biYPelsPerMeter*254L/10000; // PInfo.DPIY = PInfo.DPIY < 200 ? 200 : PInfo.DPIY; PInfo.Height = info->biHeight; PInfo.Width = info->biWidth; // PInfo.X = 0; Уже установлено // PInfo.Y = 0; PInfo.Incline2048 = 0; PInfo.Page = 1; PInfo.Angle = Angle; SetPageInfo(hCPAGE,PInfo); } //////////////////////////////////////////////////////// // Выделим компоненты // if(!ProgressStep(2,65)) rc = FALSE; if(rc) { if(LDPUMA_Skip(Image->hDebugCancelComponent)/*DPumaSkipComponent()*/) { // uchar ori; PRGTIME prev = StorePRGTIME(65, 85); rc = ExtractComponents( gbAutoRotate, NULL, (puchar)glpRecogName, Image); RestorePRGTIME(prev); /* if(rc && gbAutoRotate) { //if(!REXC_GetOrient(&ori)) //if(!REXC_GetOrient(&ori) && db_spec_prj!=SPEC_PRJ_GIP ) if(!RNORM_GetOrient(&ori, *(Image->phCCOM)) && db_spec_prj!=SPEC_PRJ_GIP ) { SetReturnCode_rstuff(RNORM_GetReturnCode()); rc = FALSE; } else { //if(ori) if(ori && !(db_spec_prj==SPEC_PRJ_GIP&&ori==4)) { uint32_t dwTurn = 0; switch(ori) { case 1: Angle = 270; dwTurn = RIMAGE_TURN_270; break; case 2: Angle = 90; dwTurn = RIMAGE_TURN_90; break; case 3: Angle = 180; dwTurn = RIMAGE_TURN_180; break; } if( LDPUMA_Skip(Image->hDebugCancelTurn) /*umaSkipTurn()*/ /*) { if(!RIMAGE_Turn((puchar)glpRecogName,(puchar)PUMA_IMAGE_TURN,dwTurn,0)) { SetReturnCode_rstuff_rstuff(RIMAGE_GetReturnCode()); rc = FALSE; } else { if(!CIMAGE_ReadDIB((puchar)PUMA_IMAGE_TURN,(Handle*)gpRecogDIB,TRUE)) { SetReturnCode_rstuff_rstuff(CIMAGE_GetReturnCode()); rc = FALSE; } else { // // удалим общий контейнер // glpRecogName = PUMA_IMAGE_TURN; hWndTurn = LDPUMA_CreateWindow(PUMA_IMAGE_TURN,(*gpRecogDIB)); PRGTIME prev = StorePRGTIME(85, 100); rc = ExtractComponents( FALSE, NULL, (puchar)glpRecogName, Image); PAGEINFO info = {0}; GetPageInfo(hCPAGE,&info); info.Images|=IMAGE_TURN; // strcpy((char*)info.szImageName,PUMA_IMAGE_TURN); SetPageInfo(hCPAGE,info); RestorePRGTIME(prev); } } } } } }*/ //проверим наличие разрешения и попытаемся определить по компонентам, если его нет checkResolution(*(Image->phCCOM), hCPAGE); if(!ProgressStep(2,100)) rc = FALSE; } else LDPUMA_Console("Пропущен этап выделения компонент.\n"); } // // Переинициализируем контейнер CPAGE // if(rc) { PAGEINFO PInfo = {0}; GetPageInfo(hCPAGE,&PInfo); strcpy((char*)PInfo.szImageName, glpRecogName); PInfo.BitPerPixel = info->biBitCount; // PInfo.DPIX = info->biXPelsPerMeter*254L/10000; PInfo.DPIX = PInfo.DPIX < 200 ? 200 : PInfo.DPIX; // PInfo.DPIY = info->biYPelsPerMeter*254L/10000; PInfo.DPIY = PInfo.DPIY < 200 ? 200 : PInfo.DPIY; PInfo.Height = info->biHeight; PInfo.Width = info->biWidth; // PInfo.X = 0; Уже установлено // PInfo.Y = 0; PInfo.Incline2048 = 0; PInfo.Page = 1; PInfo.Angle = Angle; SetPageInfo(hCPAGE,PInfo); } if(DonePRGTIME()) ProgressFinish(); return rc; }