QString ProcessControl::getBinaryPath(int pid) { qDebug() << "ProcessControl::getBinaryPath: Begin"; #ifndef WIN32 #else HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid ); if (hProcess == NULL) return QString(); LPTSTR lpExeName[256]; DWORD dwSize = 256; if (0!=GetModuleFileNameEx(hProcess,NULL,(LPTSTR)lpExeName,dwSize)) //Solo pilla la ruta del ejecutable, sin los argumentos { std::wstring exename((WCHAR*)lpExeName); std::string temp; std::copy(exename.begin(), exename.end(), std::back_inserter(temp)); qDebug() << "AAAAAAAAAAAAAAA" << temp.c_str(); return QString(temp.c_str()); } #endif return QString(); }
bool hasAntiword() { static bool searched = false, found = false; if (searched) // searched already in this run return found; QProcess *test = new QProcess(); QString exename("antiword"); #if defined(_WIN32) exename = ScPaths::instance().libDir() + "tools/antiword/antiword.exe"; #endif test->start(exename, QStringList()); if (test->waitForStarted()) { found = true; test->terminate(); std::this_thread::sleep_for(std::chrono::milliseconds(5)); test->kill(); } delete test; searched = true; return found; }
static bool do_change_version(atrt_config& config, SqlResultSet& command, AtrtClient& atrtdb){ /** * TODO make option to restart "not" initial */ uint process_id= command.columnAsInt("process_id"); const char* process_args= command.column("process_args"); g_logger.info("Change version for process: %d, args: %s", process_id, process_args); // Get the process if (process_id > config.m_processes.size()){ g_logger.critical("Invalid process id %d", process_id); return false; } atrt_process& proc= *config.m_processes[process_id]; const char* new_prefix= g_prefix1 ? g_prefix1 : g_prefix; const char* old_prefix= g_prefix; const char *start= strstr(proc.m_proc.m_path.c_str(), old_prefix); if (!start){ /* Process path does not contain old prefix. * Perhaps it contains the new prefix - e.g. is already * upgraded? */ if (strstr(proc.m_proc.m_path.c_str(), new_prefix)) { /* Process is already upgraded, *assume* that this * is ok * Alternatives could be - error, or downgrade. */ g_logger.info("Process already upgraded"); return true; } g_logger.critical("Could not find '%s' in '%s'", old_prefix, proc.m_proc.m_path.c_str()); return false; } // Save current proc state if (proc.m_save.m_saved == false) { proc.m_save.m_proc= proc.m_proc; proc.m_save.m_saved= true; } g_logger.info("stopping process..."); if (!stop_process(proc)) return false; BaseString newEnv = set_env_var(proc.m_proc.m_env, BaseString("MYSQL_BASE_DIR"), BaseString(new_prefix)); proc.m_proc.m_env.assign(newEnv); ssize_t pos = proc.m_proc.m_path.lastIndexOf('/') + 1; BaseString exename(proc.m_proc.m_path.substr(pos)); char * exe = find_bin_path(new_prefix, exename.c_str()); proc.m_proc.m_path = exe; if (exe) { free(exe); } if (process_args && strlen(process_args)) { /* Beware too long args */ proc.m_proc.m_args.append(" "); proc.m_proc.m_args.append(process_args); } { /** * In 5.5...binaries aren't compiled with rpath * So we need an explicit LD_LIBRARY_PATH * So when upgrading..we need to change LD_LIBRARY_PATH * So I hate 5.5... */ #if defined(__MACH__) ssize_t p0 = proc.m_proc.m_env.indexOf(" DYLD_LIBRARY_PATH="); #else ssize_t p0 = proc.m_proc.m_env.indexOf(" LD_LIBRARY_PATH="); #endif ssize_t p1 = proc.m_proc.m_env.indexOf(' ', p0 + 1); BaseString part0 = proc.m_proc.m_env.substr(0, p0); BaseString part1 = proc.m_proc.m_env.substr(p1); proc.m_proc.m_env.assfmt("%s%s", part0.c_str(), part1.c_str()); BaseString lib(g_libmysqlclient_so_path); ssize_t pos = lib.lastIndexOf('/') + 1; BaseString libname(lib.substr(pos)); char * exe = find_bin_path(new_prefix, libname.c_str()); char * dir = dirname(exe); #if defined(__MACH__) proc.m_proc.m_env.appfmt(" DYLD_LIBRARY_PATH=%s", dir); #else proc.m_proc.m_env.appfmt(" LD_LIBRARY_PATH=%s", dir); #endif free(exe); free(dir); } ndbout << proc << endl; g_logger.info("starting process..."); if (!start_process(proc)) return false; return true; }
DocIm::DocIm(const QString& fname, const QString& enc, bool textO, gtWriter *w) : textBuffer(this), errorBuffer(this) { filename = fname; encoding = enc; writer = w; textOnly = textO; failed = false; textBuffer.open(QIODevice::WriteOnly); errorBuffer.open(QIODevice::WriteOnly); proc = new QProcess(); QString exename("antiword"); #if defined(Q_OS_WIN32) exename = ScPaths::instance().libDir() + "tools/antiword/antiword.exe"; QString homeDir = QDir::toNativeSeparators(ScPaths::instance().libDir() + "tools"); proc->setWorkingDirectory( ScPaths::instance().libDir() + "tools/antiword/" ); proc->setEnvironment( QStringList() << QString("HOME=%1").arg(homeDir)); #endif QStringList args; args << "-t" << "-w 0"; #if defined(Q_OS_WIN32) // #10258 : use UTF-8 whenever possible if (QFile::exists(ScPaths::instance().libDir() + "tools/antiword/UTF-8.txt")) args << "-m" << "UTF-8.txt"; #endif args << QDir::toNativeSeparators(filename); //connect(proc, SIGNAL(readyReadStdout()), this, SLOT(slotReadOutput())); //connect(proc, SIGNAL(readyReadStderr()), this, SLOT(slotReadErr())); proc->start(exename, args); if (!proc->waitForStarted()) { failed = true; return; } while (proc->waitForReadyRead()) { std::this_thread::sleep_for(std::chrono::milliseconds(5)); } while (!proc->atEnd() || proc->state() == QProcess::Running) { proc->setReadChannel(QProcess::StandardOutput); if ( proc->canReadLine() ) { QByteArray bo = proc->readAllStandardOutput(); if (bo.size() > 0) textBuffer.write(bo); } else { proc->setReadChannel(QProcess::StandardError); if ( proc->canReadLine() ) { QByteArray be = proc->readAllStandardError(); if (be.size() > 0) errorBuffer.write(be); } else { std::this_thread::sleep_for(std::chrono::milliseconds(5)); } } } errorBuffer.close(); textBuffer.close(); if (proc->exitStatus() != QProcess::NormalExit) { failed = true; return; } write(); }
// 'Main program' equivalent: the program execution "starts" here bool moDirectorApp::OnInit() { //(*AppInitialize bool wxsOK = true; //*) wxInitAllImageHandlers(); // Check next line: Gustavo 05/20/2009 // return wxsOK; guint major, minor, micro, nano; cout << "Gstreamer initializing..." << endl; gst_init(NULL,NULL); gst_version (&major, &minor, µ, &nano); cout << "Gstreamer initialized" << " version: " << major << "." << minor << "." << micro << "." << nano << endl; //** SET WORKING PATH CORRECTLY **/ #if wxMAJOR_VERSION<3 wxStandardPaths StdPaths; #else wxStandardPaths StdPaths = wxStandardPaths::Get(); #endif wxFileName exename(StdPaths.GetExecutablePath()); exename.MakeAbsolute(); //wxMessageBox(wxString("appdir:")+wxString(exename.GetPath())); wxSetWorkingDirectory( wxString(exename.GetPath()) ); //** EVERYTHING OK!!!**// moDirectorCore* m_pDirectorCore = NULL; moDirectorFrame* m_pDirectorFrame = NULL; SetAppName(wxString(_("Moldeo Director ")) + moText2Wx(moGetVersionStr()) ); // Check only one instance running m_checker = NULL; /* const wxString name = wxString::Format(wxT("MoldeoDirector-%s"), wxGetUserId().c_str()); // Use mb_str() m_checker = new wxSingleInstanceChecker(name); if (m_checker->IsAnotherRunning()) { wxLogError(_("Program already running, aborting.")); return false; } */ // Check configuration file /* wxString str; wxFileConfig configuration(wxT("MoldeoDirector"),wxT("Moldeo"),wxT(wxGetCwd())); configuration.Read(wxT("General/File1"), &str); wxMessageBox(wxT(str),wxT("Moldeo Director")); */ // created initially) cout << "Image Handlers..." << endl; #if wxUSE_SYSTEM_OPTIONS //wxSystemOptions::SetOption(wxT("no-maskblt"), 1); #endif wxInitAllImageHandlers(); #if wxUSE_FS_INET && wxUSE_STREAMS && wxUSE_SOCKETS //wxFileSystem::AddHandler(new wxInternetFSHandler); #endif wxImageHandler* hndPNG = wxImage::FindHandler((long)wxBITMAP_TYPE_PNG); if (!hndPNG) cout << "Warning: PNG Image handler not loaded..." << endl; wxImageHandler* hndJPEG = wxImage::FindHandler((long)wxBITMAP_TYPE_JPEG); if (!hndJPEG) cout << "Warning: JPEG Image handler not loaded..." << endl; wxImageHandler* hndTGA = wxImage::FindHandler((long)wxBITMAP_TYPE_TGA); if (!hndTGA) cout << "Warning: TGA Image handler not loaded..." << endl; // create the main application window cout << "Director Frame..." << endl; m_pDirectorFrame = new moDirectorFrame(wxString(_("Moldeo Director ")) + moText2Wx(moGetVersionStr())); if (m_pDirectorFrame) { m_pDirectorFrame->SetIcon( wxIcon( wxIconLocation(wxT(MOLDEODATADIR "/icons/Moldeo32.ico")) ) ); m_pDirectorFrame->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_CAPTIONTEXT)); m_pDirectorFrame->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); } else { exit(1); } cout << "m_pDirectorFrame:" << (m_pDirectorFrame!=NULL) << endl; cout << "Director Core..." << endl; m_pDirectorCore = new moDirectorCore(); cout << "m_pDirectorCore:" << (m_pDirectorCore!=NULL) << endl; cout << "Director Frame UI to Core..." << endl; m_pDirectorCore->SetUserInterface( m_pDirectorFrame ); m_pDirectorCore->SetPaths( moWx2Text(exename.GetPath()), moWx2Text(StdPaths.GetUserDataDir()), moWx2Text(wxString(wxT(MODULESDIR))), moWx2Text(wxString(wxT(MOLDEODATADIR))) ); m_pDirectorCore->Init(); //wxList ImageHandlerList = wxImage::GetHandlers(); cout << "appdir:" << moWx2Text( wxGetCwd() ) << endl; cout << "userdir:" << moWx2Text( StdPaths.GetUserDataDir() ) << endl; cout << "datadir:" << moWx2Text(wxString(_(MOLDEODATADIR))) << endl; cout << "modulesdir:" << moWx2Text(wxString(_(MODULESDIR))) << endl; cout << "Showing Frame..." << endl; m_pDirectorFrame->Show(true); cout << "Setting Top Window..." << endl; SetTopWindow(m_pDirectorFrame); m_pDirectorFrame->Maximize(); m_pDirectorFrame->Init(); cout << "Success!!! rock and roll!!" << endl; moText config; cout << "argc: " << argc << endl; /*minimo 2*/ while( argc >= 2 ) { --argc; wxString arglast(argv[argc]); wxString argprev; if (argc>0) argprev = argv[argc-1]; wxString arg0(argv[0]); cout << "Argument id" << (argc) << " : " << moWx2Text(arglast) << endl; if( argprev == wxString( _("-mol") ) ) { config = moWx2Text( arglast ); cout << "Argument -mol found! : " << config << endl; --argc; } else if ( arglast == wxString(_("--help")) ) { cout << "Usage: " << moWx2Text(arg0) << " [-mol]" << endl; } else { cout << "Usage: " << moWx2Text(arg0) << " [-mol]" << endl; /*wxMessageBox( wxString(wxT("Error opening:")) + wxString(wxT(" argc:")) + // wxString(IntToStr(argc)) + wxString(wxT(" argv[argc-1]:")) + argv[argc-1] + wxString(wxT(" argv[0]:")) + wxString(argv[0]) + wxString(wxT(" argv[1]:")) + wxString(argv[1]) + wxString(wxT(" argv[2]:")) + wxString(argv[2]) ); */ //exit(0); } } if (config!=moText("")) { moProjectDescriptor ProjectDescriptor; wxFileName FileName( moText2Wx(config) ); wxString path = FileName.GetPath(); #ifdef MO_WIN32 path+= _T("\\"); #else path+= _T("/"); #endif wxString name = FileName.GetFullName(); ProjectDescriptor.Set( moWx2Text(path), moWx2Text(name) ); moDirectorStatus mStatus = m_pDirectorFrame->OpenProject( ProjectDescriptor ); } // success: wxApp::OnRun() will be called which will enter the main message // loop and the application will run. If we returned false here, the // application would exit immediately. return true; }