Ejemplo n.º 1
0
wxDebugReport::wxDebugReport()
{
    // get a temporary directory name
    wxString appname = GetReportName();

    // we can't use CreateTempFileName() because it creates a file, not a
    // directory, so do our best to create a unique name ourselves
    //
    // of course, this doesn't protect us against malicious users...
    wxFileName fn;
    fn.AssignTempFileName(appname);
#if wxUSE_DATETIME
    m_dir.Printf(wxT("%s%c%s_dbgrpt-%lu-%s"),
                 fn.GetPath().c_str(), wxFILE_SEP_PATH, appname.c_str(),
                 wxGetProcessId(),
                 wxDateTime::Now().Format(wxT("%Y%m%dT%H%M%S")).c_str());
#else
    m_dir.Printf(wxT("%s%c%s_dbgrpt-%lu"),
                 fn.GetPath().c_str(), wxFILE_SEP_PATH, appname.c_str(),
                 wxGetProcessId());
#endif

    // as we are going to save the process state there use restrictive
    // permissions
    if ( !wxMkdir(m_dir, 0700) )
    {
        wxLogSysError(_("Failed to create directory \"%s\""), m_dir.c_str());
        wxLogError(_("Debug report couldn't be created."));

        Reset();
    }
}
Ejemplo n.º 2
0
wxString
wxPdfUtility::GetUniqueId(const wxString& prefix)
{
  wxString uid = (prefix.Length() <= 114) ? prefix : prefix.Left(114);

  wxDateTime ts;
  ts.SetToCurrent();

  int q;
  int z;
  if (!ms_seeded)
  {
    ms_seeded = true;
    ms_s1 = ts.GetSecond() ^ (~ts.GetMillisecond());
    if (ms_s1 == 0) ms_s1 = 1;
    ms_s2 = wxGetProcessId();
  }
  MODMULT(53668, 40014, 12211, 2147483563L, ms_s1);
  MODMULT(52774, 40692,  3791, 2147483399L, ms_s2);

  z = ms_s1 - ms_s2;
  if (z < 1)
  {
    z += 2147483562;
  }

  uid += wxString::Format(wxT("%08x%05x"), ts.GetSecond(), ts.GetMillisecond());
  uid += Double2String(z * 4.656613e-9,8);

  return uid;
}
Ejemplo n.º 3
0
void AttachDbgProcDlg::RefreshProcessesList(wxString filter, int colToSort)
{
    wxWindowUpdateLocker locker(m_dvListCtrl);
    m_dvListCtrl->DeleteAllItems();

    filter.Trim().Trim(false);

    // Populate the list with list of processes
    std::vector<ProcessEntry> proclist;
    ProcUtils::GetProcessList(proclist);

    //    if(colToSort == 0) { // sort by PID
    //        std::sort(proclist.begin(), proclist.end(), PIDSorter());
    //
    //    } else if(colToSort == 1) { // sort by name
    //        std::sort(proclist.begin(), proclist.end(), NameSorter());
    //    }

    filter.MakeLower();
    for(size_t i = 0; i < proclist.size(); ++i) {

        // Use case in-sensitive match for the filter
        wxString entryName(proclist.at(i).name);

        // Append only processes that matches the filter string
        if(filter.IsEmpty() || FileUtils::FuzzyMatch(filter, entryName)) {
            const ProcessEntry& entry = proclist.at(i);
            if(entry.pid == (long)wxGetProcessId()) continue;
            wxVector<wxVariant> cols;
            cols.push_back(wxString() << entry.pid);
            cols.push_back(entry.name);
            m_dvListCtrl->AppendItem(cols);
        }
    }
}
Ejemplo n.º 4
0
int ConsoleFinder::RunConsole(const wxString &title)
{
	// start the xterm and put the shell to sleep with -e sleep 80000
	// fetch the xterm tty so we can issue to gdb a "tty /dev/pts/#"
	// redirecting program stdin/stdout/stderr to the xterm console.

#ifndef __WXMSW__
	wxString cmd;

	cmd = GetConsoleCommand();
	cmd.Replace(wxT("$(TITLE)"), title);
	cmd.Replace(wxT("$(CMD)"), wxString::Format(wxT("sleep %lu"), 80000 + wxGetProcessId()));

	wxLogMessage(wxString::Format(wxT("Launching console: %s"), cmd.c_str()));

	m_nConsolePid = wxExecute(cmd, wxEXEC_ASYNC|wxEXEC_MAKE_GROUP_LEADER);
	if (m_nConsolePid <= 0) {
		return -1;
	}

	// Issue the PS command to get the /dev/tty device name
	// First, wait for the xterm to settle down, else PS won't see the sleep task
	wxSleep(1);
	m_ConsoleTty = GetConsoleTty(m_nConsolePid);
	if (m_ConsoleTty.IsEmpty()) {
		FreeConsole();
		return -1;
	}
	return m_nConsolePid;

#else //__WXMSW__
	wxUnusedVar(title);
	return -1;
#endif
}
Ejemplo n.º 5
0
wxString wxTarOutputStream::PaxHeaderPath(const wxString& format,
                                          const wxString& path)
{
    wxString d = path.BeforeLast(wxT('/'));
    wxString f = path.AfterLast(wxT('/'));
    wxString ret;

    if (d.empty())
        d = wxT(".");

    ret.reserve(format.length() + path.length() + 16);

    size_t begin = 0;

    for (;;) {
        size_t end;
        end = format.find('%', begin);
        if (end == wxString::npos || end + 1 >= format.length())
            break;
        ret << format.substr(begin, end - begin);
        switch ( format[end + 1].GetValue() ) {
            case 'd': ret << d; break;
            case 'f': ret << f; break;
            case 'p': ret << wxGetProcessId(); break;
            case '%': ret << wxT("%"); break;
        }
        begin = end + 2;
    }

    ret << format.substr(begin);

    return ret;
}
Ejemplo n.º 6
0
CRemoteDataObject::CRemoteDataObject(const CServer& server, const CServerPath& path)
	: wxDataObjectSimple(wxDataFormat(_T("FileZilla3RemoteDataObject")))
	, m_server(server)
	, m_path(path)
	, m_didSendData()
	, m_processId(wxGetProcessId())
{
}
Ejemplo n.º 7
0
/**
 * 終了後の後始末
 */
int MyApp::OnExit() {

     unsigned long pid = wxGetProcessId();

     if (HelloWorld::doRestart) {
	  wxString execute = wxGetCwd() + wxT("/HelloWorld");
	  ::wxExecute(execute + wxString::Format(_(" -p %lu"), pid), wxEXEC_ASYNC, NULL);
     }

     return 0;
}
Ejemplo n.º 8
0
bool androidGetMemoryStatus( int *mem_total, int *mem_used )
{
    
    //  On android, We arbitrarilly declare that we have used 50% of available memory.
    if(mem_total)
        *mem_total = 100 * 1024;
    if(mem_used)
        *mem_used = 50 * 1024;
    return true;
    
#if 0
    
    //  Get a reference to the running native activity
    QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative",
                                                                           "activity", "()Landroid/app/Activity;");
    
    if ( !activity.isValid() ){
        qDebug() << "Activity is not valid";
        return false;
    }

    unsigned long android_processID = wxGetProcessId();
    
    //  Call the desired method
    QAndroidJniObject data = activity.callObjectMethod("getMemInfo", "(I)Ljava/lang/String;", (int)android_processID);
    
//    wxString return_string;
    jstring s = data.object<jstring>();
    
    int mu = 50;
    //  Need a Java environment to decode the resulting string
    if (java_vm->GetEnv( (void **) &jenv, JNI_VERSION_1_6) != JNI_OK) {
        qDebug() << "GetEnv failed.";
    }
    else {
        const char *ret_string = (jenv)->GetStringUTFChars(s, NULL);
        mu = atoi(ret_string);
        
    }
    
    if(mem_used)
        *mem_used = mu;

        
    return true;
#endif    
}
Ejemplo n.º 9
0
	virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def)
	{
		if (def == wxDragError ||
			def == wxDragNone ||
			def == wxDragCancel)
			return def;
		if( def == wxDragLink ) {
			def = wxDragCopy;
		}

		wxTreeItemId hit = GetHit(wxPoint(x, y));
		if (!hit)
			return wxDragNone;

		const CLocalPath path(GetDirFromItem(hit));
		if (path.empty() || !path.IsWriteable())
			return wxDragNone;

		if (!GetData())
			return wxDragError;

		CDragDropManager* pDragDropManager = CDragDropManager::Get();
		if (pDragDropManager)
			pDragDropManager->pDropTarget = m_pLocalTreeView;

		if (m_pDataObject->GetReceivedFormat() == m_pFileDataObject->GetFormat())
			m_pLocalTreeView->m_pState->HandleDroppedFiles(m_pFileDataObject, path, def == wxDragCopy);
		else
		{
			if (m_pRemoteDataObject->GetProcessId() != (int)wxGetProcessId())
			{
				wxMessageBoxEx(_("Drag&drop between different instances of FileZilla has not been implemented yet."));
				return wxDragNone;
			}

			if (!m_pLocalTreeView->m_pState->GetServer() || !m_pRemoteDataObject->GetServer().EqualsNoPass(*m_pLocalTreeView->m_pState->GetServer()))
			{
				wxMessageBoxEx(_("Drag&drop between different servers has not been implemented yet."));
				return wxDragNone;
			}

			if (!m_pLocalTreeView->m_pState->DownloadDroppedFiles(m_pRemoteDataObject, path))
				return wxDragNone;
		}

		return def;
	}
Ejemplo n.º 10
0
bool CLogging::InitLogFile(fz::scoped_lock& l) const
{
	if (m_logfile_initialized)
		return true;

	m_logfile_initialized = true;

	m_file = engine_.GetOptions().GetOption(OPTION_LOGGING_FILE);
	if (m_file.empty())
		return false;

#ifdef __WXMSW__
	m_log_fd = CreateFile(m_file.wc_str(), FILE_APPEND_DATA, FILE_SHARE_DELETE | FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
	if (m_log_fd == INVALID_HANDLE_VALUE)
#else
	m_log_fd = open(m_file.fn_str(), O_WRONLY | O_APPEND | O_CREAT | O_CLOEXEC, 0644);
	if (m_log_fd == -1)
#endif
	{
		l.unlock(); //Avoid recursion
		LogMessage(MessageType::Error, _("Could not open log file: %s"), wxSysErrorMsg());
		return false;
	}

	m_prefixes[static_cast<int>(MessageType::Status)] = _("Status:");
	m_prefixes[static_cast<int>(MessageType::Error)] = _("Error:");
	m_prefixes[static_cast<int>(MessageType::Command)] = _("Command:");
	m_prefixes[static_cast<int>(MessageType::Response)] = _("Response:");
	m_prefixes[static_cast<int>(MessageType::Debug_Warning)] = _("Trace:");
	m_prefixes[static_cast<int>(MessageType::Debug_Info)] = m_prefixes[static_cast<int>(MessageType::Debug_Warning)];
	m_prefixes[static_cast<int>(MessageType::Debug_Verbose)] = m_prefixes[static_cast<int>(MessageType::Debug_Warning)];
	m_prefixes[static_cast<int>(MessageType::Debug_Debug)] = m_prefixes[static_cast<int>(MessageType::Debug_Warning)];
	m_prefixes[static_cast<int>(MessageType::RawList)] = _("Listing:");

	m_pid = wxGetProcessId();

	m_max_size = engine_.GetOptions().GetOptionVal(OPTION_LOGGING_FILE_SIZELIMIT);
	if (m_max_size < 0)
		m_max_size = 0;
	else if (m_max_size > 2000)
		m_max_size = 2000;
	m_max_size *= 1024 * 1024;

	return true;
}
Ejemplo n.º 11
0
void Console::logToFile(const LogMessage& message) {
#if defined __APPLE__
    NSLogWrapper(message.string());
#else
    IO::FileManager fileManager;
    const String logDirectory = fileManager.logDirectory();
    if (logDirectory.empty())
        return;
    if (!fileManager.exists(logDirectory))
        fileManager.makeDirectory(logDirectory);
    const String logFilePath = fileManager.appendPath(logDirectory, "TrenchBroom.log");
    std::fstream logStream(logFilePath.c_str(), std::ios::out | std::ios::app);
    if (logStream.is_open()) {
        wxDateTime now = wxDateTime::Now();
        logStream << wxGetProcessId() << " " << now.FormatISOCombined(' ') << ": " << message.string() << std::endl;
    }
#endif
}
Ejemplo n.º 12
0
int wxKill(long pid, wxSignal sig, wxKillError *rc, int WXUNUSED(flags))
{
    int result = -1;

    if (pid != (long)wxGetProcessId())
    {
        result = raise(sig);
        if (rc)
            *rc = result == 0 ? wxKILL_OK : wxKILL_BAD_SIGNAL;
    }
    else
    {
        wxLogDebug(wxT("wxKill can only send signals to the current process under MSDOS"));
        if (rc)
            *rc = wxKILL_NO_PROCESS;
    }

    return result;
}
Ejemplo n.º 13
0
void CLogging::InitLogFile() const
{
	if (m_logfile_initialized)
		return;

	m_logfile_initialized = true;

	m_file = m_pEngine->GetOptions()->GetOption(OPTION_LOGGING_FILE);
	if (m_file == _T(""))
		return;

#ifdef __WXMSW__
	m_log_fd = CreateFile(m_file, FILE_APPEND_DATA, FILE_SHARE_DELETE | FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
	if (m_log_fd == INVALID_HANDLE_VALUE)
#else
	m_log_fd = open(m_file.fn_str(), O_WRONLY | O_APPEND | O_CREAT, 0644);
	if (m_log_fd == -1)
#endif
	{
		LogMessage(Error, _("Could not open log file: %s"), wxSysErrorMsg());
		return;
	}

	m_prefixes[Status] = _("Status:");
	m_prefixes[Error] = _("Error:");
	m_prefixes[Command] = _("Command:");
	m_prefixes[Response] = _("Response:");
	m_prefixes[Debug_Warning] = _("Trace:");
	m_prefixes[Debug_Info] = m_prefixes[Debug_Warning];
	m_prefixes[Debug_Verbose] = m_prefixes[Debug_Warning];
	m_prefixes[Debug_Debug] = m_prefixes[Debug_Warning];
	m_prefixes[RawList] = _("Listing:");

	m_pid = wxGetProcessId();

	m_max_size = m_pEngine->GetOptions()->GetOptionVal(OPTION_LOGGING_FILE_SIZELIMIT);
	if (m_max_size < 0)
		m_max_size = 0;
	else if (m_max_size > 2000)
		m_max_size = 2000;
	m_max_size *= 1024 * 1024;
}
Ejemplo n.º 14
0
	virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def)
	{
		if (def == wxDragError ||
			def == wxDragNone ||
			def == wxDragCancel)
			return def;

		wxTreeItemId hit = GetHit(wxPoint(x, y));
		if (!hit)
			return wxDragNone;

		wxString dir = GetDirFromItem(hit);
		if (dir == _T("") || !CState::LocalDirIsWriteable(dir))
			return wxDragNone;

		if (!GetData())
			return wxDragError;

		if (m_pDataObject->GetReceivedFormat() == m_pFileDataObject->GetFormat())
			m_pLocalTreeView->m_pState->HandleDroppedFiles(m_pFileDataObject, dir, def == wxDragCopy);
		else
		{
			if (m_pRemoteDataObject->GetProcessId() != (int)wxGetProcessId())
			{
				wxMessageBox(_("Drag&drop between different instances of FileZilla has not been implemented yet."));
				return wxDragNone;
			}

			if (!m_pLocalTreeView->m_pState->GetServer() || m_pRemoteDataObject->GetServer() != *m_pLocalTreeView->m_pState->GetServer())
			{
				wxMessageBox(_("Drag&drop between different servers has not been implemented yet."));
				return wxDragNone;
			}

			if (!m_pLocalTreeView->m_pState->DownloadDroppedFiles(m_pRemoteDataObject, dir))
				return wxDragNone;
		}

		return def;
	}
void sysLogger::WriteLog(const wxString& msg)
{
    wxString pid, logfile;

    // Disable logging to prevent recursion in the event of a problem
    wxLogNull foo;

    pid.Printf(wxT("%ld"), wxGetProcessId());
    logfile.Printf(wxT("%s"), logFile.c_str());
    logfile.Replace(wxT("%ID"), pid);

    wxFFile file(logfile, wxT("a"));

#if !defined(PGSCLI)
    if (!file.IsOpened()) {
        wxMessageBox(_("Cannot open the logfile!"), _("FATAL"), wxOK | wxCENTRE | wxICON_ERROR);
        return;
    }
#endif // PGSCLI

   file.Write(msg + wxT("\n"));
   file.Close();
}
Ejemplo n.º 16
0
    void wxLuaSocketDebugMsg(const wxString& title, const wxString& msg)
    {
#ifdef __WXMSW__ // no console in MSW
        wxLuaCharBuffer buf(wxString::Format(wxT("%s PID %ld TIME %s %s\n"), title.c_str(), (long)wxGetProcessId(), wxT(__TIME__), msg.c_str()));
        FILE* h = fopen("wxLua_socketdebug.log", "a");
        fprintf(h, buf.GetData());
        fclose(h);
#else  // !__WXMSW__
        wxSafeShowMessage(title, wxString::Format(wxT("PID %ld TIME %s\n\t%s"), (long)wxGetProcessId(), wxT(__TIME__), msg.c_str()));
#endif // __WXMSW__
    }
Ejemplo n.º 17
0
wxLuaDebugTarget::wxLuaDebugTarget(const wxLuaState& wxlState,
                                   const wxString &serverName,
                                   int             port_number) :
    m_wxlState(wxlState),
    m_port_number(port_number),
    m_serverName(serverName),
    m_debugCondition(m_debugMutex),
    m_forceBreak(false),
    m_resetRequested(false),
    m_fConnected(false),
    m_fRunning(false),
    m_fStopped(false),
    m_fExiting(false),
    m_fErrorsSeen(false),
    m_nFramesUntilBreak(0),
    m_runCondition(m_runMutex),
    m_pThread(NULL)
{
    m_clientSocket.m_name = wxString::Format(wxT("wxLuaDebugTarget::m_clientSocket (%ld)"), (long)wxGetProcessId());

    lua_State* L = m_wxlState.GetLuaState();
    // Stick us into the lua_State - push key, value
    lua_pushstring( L, "__wxLuaDebugTarget__" );
    lua_pushlightuserdata( L, (void*)this );
    // set the value
    lua_rawset( L, LUA_REGISTRYINDEX );

    lua_sethook(L, LuaDebugHook, LUA_MASKCALL | LUA_MASKLINE | LUA_MASKRET, 0);

    lua_pushcfunction(L, LuaPrint);
    lua_setglobal(L, "print");

    EnterLuaCriticalSection();
}
Ejemplo n.º 18
0
mux_dialog::mux_dialog(wxWindow *parent):
    wxDialog(parent, -1, Z("mkvmerge is running"), wxDefaultPosition,
#ifdef SYS_WINDOWS
             wxSize(700, 560),
#else
             wxSize(700, 520),
#endif
             wxDEFAULT_FRAME_STYLE)
#if defined(SYS_WINDOWS)
    , pid(0)
    , m_taskbar_progress(NULL)
    , m_abort_button_changed(false)
#endif  // SYS_WINDOWS
    , m_exit_code(0)
    , m_progress(0)
{
    char c;
    std::string arg_utf8, line;
    long value;
    wxString wx_line, tmp;
    wxInputStream *out;
    wxFile *opt_file;
    uint32_t i;
    wxArrayString *arg_list;
    wxBoxSizer *siz_all, *siz_buttons, *siz_line;
    wxStaticBoxSizer *siz_status, *siz_output;

    m_window_disabler = new wxWindowDisabler(this);

    c = 0;
    siz_status = new wxStaticBoxSizer(new wxStaticBox(this, -1, Z("Status and progress")), wxVERTICAL);
    st_label = new wxStaticText(this, -1, wxEmptyString);
    st_remaining_time_label = new wxStaticText(this, -1, Z("Remaining time:"));
    st_remaining_time       = new wxStaticText(this, -1, Z("is being estimated"));
    siz_line = new wxBoxSizer(wxHORIZONTAL);
    siz_line->Add(st_label);
    siz_line->AddSpacer(5);
    siz_line->Add(st_remaining_time_label);
    siz_line->AddSpacer(5);
    siz_line->Add(st_remaining_time);
    siz_status->Add(siz_line, 0, wxGROW | wxALIGN_LEFT | wxALL, 5);
    g_progress = new wxGauge(this, -1, 100, wxDefaultPosition, wxSize(250, 15));
    siz_status->Add(g_progress, 1, wxALL | wxGROW, 5);

    siz_output = new wxStaticBoxSizer(new wxStaticBox(this, -1, Z("Output")), wxVERTICAL);
    siz_output->Add(new wxStaticText(this, -1, Z("mkvmerge output:")), 0, wxALIGN_LEFT | wxALL, 5);
    tc_output = new wxTextCtrl(this, -1, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY | wxTE_BESTWRAP | wxTE_MULTILINE);
    siz_output->Add(tc_output, 2, wxGROW | wxALL, 5);
    siz_output->Add(new wxStaticText(this, -1, Z("Warnings:")), 0, wxALIGN_LEFT | wxALL, 5);
    tc_warnings = new wxTextCtrl(this, -1, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY | wxTE_BESTWRAP | wxTE_MULTILINE);
    siz_output->Add(tc_warnings, 1, wxGROW | wxALL, 5);
    siz_output->Add(new wxStaticText(this, -1, Z("Errors:")), 0, wxALIGN_LEFT | wxALL, 5);
    tc_errors = new wxTextCtrl(this, -1, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY | wxTE_BESTWRAP | wxTE_MULTILINE);
    siz_output->Add(tc_errors, 1, wxGROW | wxALL, 5);

    siz_buttons = new wxBoxSizer(wxHORIZONTAL);
    siz_buttons->AddStretchSpacer();
    b_ok = new wxButton(this, ID_B_MUX_OK, Z("Ok"));
    b_ok->Enable(false);
    siz_buttons->Add(b_ok, 0, wxGROW);
    siz_buttons->AddStretchSpacer();
    b_abort = new wxButton(this, ID_B_MUX_ABORT, Z("Abort"));
    siz_buttons->Add(b_abort, 0, wxGROW);
    siz_buttons->AddStretchSpacer();
    b_save_log = new wxButton(this, ID_B_MUX_SAVELOG, Z("Save log"));
    siz_buttons->Add(b_save_log, 0, wxGROW);
    siz_buttons->AddStretchSpacer();

    siz_all = new wxBoxSizer(wxVERTICAL);
    siz_all->Add(siz_status, 0, wxGROW | wxALL, 5);
    siz_all->Add(siz_output, 1, wxGROW | wxALL, 5);
    siz_all->Add(siz_buttons, 0, wxGROW | wxALL, 10);
    SetSizer(siz_all);

    update_window(Z("Muxing in progress."));
    Show(true);

    process = new mux_process(this);

    opt_file_name.Printf(wxT("%smmg-mkvmerge-options-%d-%d"), get_temp_dir().c_str(), (int)wxGetProcessId(), (int)wxGetUTCTime());
    try {
        const unsigned char utf8_bom[3] = {0xef, 0xbb, 0xbf};
        opt_file = new wxFile(opt_file_name, wxFile::write);
        opt_file->Write(utf8_bom, 3);
    } catch (...) {
        wxString error;
        error.Printf(Z("Could not create a temporary file for mkvmerge's command line option called '%s' (error code %d, %s)."), opt_file_name.c_str(), errno, wxUCS(strerror(errno)));
        wxMessageBox(error, Z("File creation failed"), wxOK | wxCENTER | wxICON_ERROR);
        throw 0;
    }
    arg_list = &static_cast<mmg_dialog *>(parent)->get_command_line_args();
    for (i = 1; i < arg_list->Count(); i++) {
        if ((*arg_list)[i].Length() == 0)
            opt_file->Write(wxT("#EMPTY#"));
        else {
            arg_utf8 = escape(wxMB((*arg_list)[i]));
            opt_file->Write(arg_utf8.c_str(), arg_utf8.length());
        }
        opt_file->Write(wxT("\n"));
    }
    delete opt_file;

#if defined(SYS_WINDOWS)
    if (get_windows_version() >= WINDOWS_VERSION_7) {
        m_taskbar_progress = new taskbar_progress_c(mdlg);
        m_taskbar_progress->set_state(TBPF_NORMAL);
        m_taskbar_progress->set_value(0, 100);
    }
#endif  // SYS_WINDOWS

    m_start_time                 = get_current_time_millis();
    m_next_remaining_time_update = m_start_time + 8000;

    wxString command_line = wxString::Format(wxT("\"%s\" \"@%s\""), (*arg_list)[0].c_str(), opt_file_name.c_str());
    pid = wxExecute(command_line, wxEXEC_ASYNC, process);
    if (0 == pid) {
        wxLogError(wxT("Execution of '%s' failed."), command_line.c_str());
        done(2);
        return;
    }
    out = process->GetInputStream();

    line = "";
    log = wxEmptyString;
    while (1) {
        while (app->Pending())
            app->Dispatch();

        if (!out->CanRead() && !out->Eof()) {
            wxMilliSleep(5);
            continue;
        }

        if (!out->Eof())
            c = out->GetC();
        else
            c = '\n';

        if ((c == '\n') || (c == '\r') || out->Eof()) {
            wx_line = wxU(line);
            log += wx_line;
            if (c != '\r')
                log += wxT("\n");
            if (wx_line.Find(Z("Warning:")) == 0)
                tc_warnings->AppendText(wx_line + wxT("\n"));
            else if (wx_line.Find(Z("Error:")) == 0)
                tc_errors->AppendText(wx_line + wxT("\n"));
            else if (wx_line.Find(Z("Progress")) == 0) {
                if (wx_line.Find(wxT("%")) != 0) {
                    wx_line.Remove(wx_line.Find(wxT("%")));
                    tmp = wx_line.AfterLast(wxT(' '));
                    tmp.ToLong(&value);
                    if ((value >= 0) && (value <= 100))
                        update_gauge(value);
                }
            } else if (wx_line.Length() > 0)
                tc_output->AppendText(wx_line + wxT("\n"));
            line = "";

            update_remaining_time();

        } else if ((unsigned char)c != 0xff)
            line += c;

        if (out->Eof())
            break;
    }
}
Ejemplo n.º 19
0
	virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def)
	{
		if (def == wxDragError ||
			def == wxDragNone ||
			def == wxDragCancel)
			return def;

		if (m_pLocalListView->m_fileData.empty())
			return wxDragError;

		if (def != wxDragCopy && def != wxDragMove)
			return wxDragError;

		CDragDropManager* pDragDropManager = CDragDropManager::Get();
		if (pDragDropManager)
			pDragDropManager->pDropTarget = m_pLocalListView;

		wxString subdir;
		int flags;
		int hit = m_pLocalListView->HitTest(wxPoint(x, y), flags, 0);
		if (hit != -1 && (flags & wxLIST_HITTEST_ONITEM))
		{
			const CLocalFileData* const data = m_pLocalListView->GetData(hit);
			if (data && data->dir)
				subdir = data->name;
		}

		CLocalPath dir = m_pLocalListView->m_pState->GetLocalDir();
		if (subdir != _T(""))
		{
			if (!dir.ChangePath(subdir))
				return wxDragError;
		}

		if (!dir.IsWriteable())
			return wxDragError;

		if (!GetData())
			return wxDragError;

		if (m_pDataObject->GetReceivedFormat() == m_pFileDataObject->GetFormat())
			m_pLocalListView->m_pState->HandleDroppedFiles(m_pFileDataObject, dir, def == wxDragCopy);
		else
		{
			if (m_pRemoteDataObject->GetProcessId() != (int)wxGetProcessId())
			{
				wxMessageBoxEx(_("Drag&drop between different instances of FileZilla has not been implemented yet."));
				return wxDragNone;
			}

			if (!m_pLocalListView->m_pState->GetServer() || !m_pRemoteDataObject->GetServer().EqualsNoPass(*m_pLocalListView->m_pState->GetServer()))
			{
				wxMessageBoxEx(_("Drag&drop between different servers has not been implemented yet."));
				return wxDragNone;
			}

			if (!m_pLocalListView->m_pState->DownloadDroppedFiles(m_pRemoteDataObject, dir))
				return wxDragNone;
		}

		return def;
	}
Ejemplo n.º 20
0
CRemoteDataObject::CRemoteDataObject()
	: wxDataObjectSimple(wxDataFormat(_T("FileZilla3RemoteDataObject")))
	, m_didSendData()
	, m_processId(wxGetProcessId())
{
}
Ejemplo n.º 21
0
void wxLuaDebuggerwxSocketServer::OnServerEvent(wxSocketEvent& event)
{
    switch(event.GetSocketEvent())
    {
        case wxSOCKET_CONNECTION:
        {
            wxSocketBase *sock = m_serverSocket->Accept(false);
            if (!sock)
            {
                // Error
                return;
            }

            sock->SetFlags(wxSOCKET_NOWAIT);
            m_acceptedSocket = new wxLuawxSocket(sock);
            m_acceptedSocket->m_port_number = m_port_number; // can't get it from wxSocketBase
            m_acceptedSocket->m_name = wxString::Format(wxT("wxLuaDebuggerwxSocketServer::m_acceptedSocket (%ld)"), (long)wxGetProcessId());

            // Setup Handler
            sock->SetEventHandler(*this, ID_WXLUA_SOCKET);
            sock->SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG);
            sock->Notify(true);

            wxMilliSleep(500);

            // Notify that a client has connected and we are ready to debug
            wxLuaDebuggerEvent debugEvent(wxEVT_WXLUA_DEBUGGER_DEBUGGEE_CONNECTED, this);
            AddPendingEvent(debugEvent);

            break;
        }

        default:
            // Error
            break;
    }
}
Ejemplo n.º 22
0
void wxLuaDebuggerCServer::ThreadFunction()
{
    wxCHECK_RET(m_serverSocket, wxT("Invalid server socket"));
    wxCHECK_RET(m_acceptedSocket == NULL, wxT("The debugger server has already accepted a socket connection"));

    m_acceptedSocket = m_serverSocket->Accept();
    if (!m_acceptedSocket)
    {
        wxLuaDebuggerEvent debugEvent(wxEVT_WXLUA_DEBUGGER_ERROR, this);
        debugEvent.SetMessage(m_serverSocket->GetErrorMsg(true));
        AddPendingEvent(debugEvent);
    }
    else
    {
        m_acceptedSocket->m_name = wxString::Format(wxT("wxLuaDebuggerCServer::m_acceptedSocket (%ld)"), (long)wxGetProcessId());

        wxLuaSocket *serverSocket = m_serverSocket;
        m_serverSocket = NULL;
        delete serverSocket;

        wxThread::Sleep(500);  // why ??

        // Notify that a client has connected and we are ready to debug
        wxLuaDebuggerEvent debugEvent(wxEVT_WXLUA_DEBUGGER_DEBUGGEE_CONNECTED, this);
        AddPendingEvent(debugEvent);

        unsigned char debug_event = 0; // wxLuaDebuggeeEvents_Type

        // Enter the debug loop
        while (!m_pThread->TestDestroy() && !m_shutdown && m_acceptedSocket)
        {
            debug_event = wxLUA_DEBUGGEE_EVENT_EXIT;

            {
                // lock the critical section while we access it
                wxCriticalSectionLocker locker(m_acceptSockCritSect);
                if (m_shutdown || (m_acceptedSocket == NULL) || !m_acceptedSocket->ReadCmd(debug_event))
                {
                    m_shutdown = true;
                    break;
                }
            }

            if((debug_event == wxLUA_DEBUGGEE_EVENT_EXIT) ||
               (HandleDebuggeeEvent(debug_event) != -1))
            {
                // don't send exit event until we've closed the socket
                if (debug_event == wxLUA_DEBUGGEE_EVENT_EXIT)
                {
                    m_shutdown = true;
                    break;
                }
            }
        }

        wxCriticalSectionLocker locker(m_acceptSockCritSect);
        // delete the accepted socket
        if (m_acceptedSocket != NULL)
        {
            wxLuaSocket *acceptedSocket = m_acceptedSocket;
            m_acceptedSocket = NULL;
            delete acceptedSocket;
        }
    }

    // Send the exit event, now that everything is shut down
    //if (debug_event == wxLUA_DEBUGGEE_EVENT_EXIT)
    {
        wxLuaDebuggerEvent debugEvent(wxEVT_WXLUA_DEBUGGER_EXIT, this);
        wxPostEvent(this, debugEvent);
    }
}
Ejemplo n.º 23
0
unsigned long bmx_wxgetprocessid() {
	return wxGetProcessId();
}
Ejemplo n.º 24
0
bool wxLuaDebuggerCServer::StartServer()
{
    wxCHECK_MSG(m_serverSocket == NULL, false, wxT("Debugger server socket already created"));

    m_shutdown = false;
    m_serverSocket = new wxLuaCSocket();
    m_serverSocket->m_name = wxString::Format(wxT("wxLuaDebuggerCServer::m_serverSocket (%ld)"), (long)wxGetProcessId());

    if (m_serverSocket->Listen(m_port_number))
    {
        wxCHECK_MSG(m_pThread == NULL, false, wxT("Debugger server thread already created"));

        if (!m_shutdown)
        {
            m_pThread = new wxLuaDebuggerCServer::LuaThread(this);

            return ((m_pThread != NULL) &&
                    (m_pThread->Create() == wxTHREAD_NO_ERROR) &&
                    (m_pThread->Run()    == wxTHREAD_NO_ERROR));
        }
    }
    else
    {
        wxLuaDebuggerEvent debugEvent(wxEVT_WXLUA_DEBUGGER_ERROR, this);
        debugEvent.SetMessage(m_serverSocket->GetErrorMsg(true));
        AddPendingEvent(debugEvent);

        delete m_serverSocket;
        m_serverSocket = NULL;
        m_shutdown = true;
    }

    return false;
}
Ejemplo n.º 25
0
int bmx_wxgetprocessid() {
	return wxGetProcessId();
}
Ejemplo n.º 26
0
bool androidGetMemoryStatus( int *mem_total, int *mem_used )
{
    
    if(mem_total)
        *mem_total = 100 * 1024;
    if(mem_used)
        *mem_used = 50 * 1024;
    
#if 0
        
        
    unsigned long android_processID = wxGetProcessId();
        
        QAndroidJniObject data = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/bindings/QtActivity",
        "callFromCpp",
        "(I)Ljava/lang/String;",
        (int) android_processID);
        
        //   jint x = data.object<jint>();
        //   int x = reinterpret_cast<int>(data.object<int>());
        jstring f = data.object<jstring>();
        
        
        //     jint x = QAndroidJniObject::callStaticObjectMethod<jint>("org/qtproject/qt5/appActivity",
        //                                                                        "callFromCpp");
        
        if (java_vm->GetEnv( (void **) &jenv, JNI_VERSION_1_6) != JNI_OK) {
            qDebug() << "GetEnv failed.";
            return -1;
}

int mu = 0;
const char *ret_val = (jenv)->GetStringUTFChars(f, NULL);
if (ret_val != NULL) {
    
    qDebug() << "Mem" << ret_val;
    
    mu = atoi(ret_val);
    
    (jenv)->ReleaseStringUTFChars(f, ret_val);
}

if(mem_total)
    *mem_total = 100 * 1024;
if(mem_used)
    *mem_used = mu;

//    if(mem_used)
    //        qDebug() << "Mem Status" << (*mem_used) / 1024  ;
    #endif

    
    //  Get a reference to the running native activity
    QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative",
                                                                           "activity", "()Landroid/app/Activity;");
    
    if ( !activity.isValid() ){
        qDebug() << "Activity is not valid";
        return false;
    }

    unsigned long android_processID = wxGetProcessId();
    
    //  Call the desired method
    QAndroidJniObject data = activity.callObjectMethod("getMemInfo", "(I)Ljava/lang/String;", (int)android_processID);
    
//    wxString return_string;
    jstring s = data.object<jstring>();
    
    int mu = 100;
    //  Need a Java environment to decode the resulting string
    if (java_vm->GetEnv( (void **) &jenv, JNI_VERSION_1_6) != JNI_OK) {
        qDebug() << "GetEnv failed.";
    }
    else {
        const char *ret_string = (jenv)->GetStringUTFChars(s, NULL);
        mu = atoi(ret_string);
        
//        return_string = wxString(ret_string, wxConvUTF8);
    }
    
    if(mem_used)
        *mem_used = mu;

//    if(mem_used)
//        qDebug() << "Mem Status" << (*mem_used) / 1024  ;
        
    return true;
}
Ejemplo n.º 27
0
	virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def)
	{
		if (def == wxDragError ||
			def == wxDragNone ||
			def == wxDragCancel)
			return def;

		if (m_pLocalListView->m_fileData.empty())
			return wxDragError;

		if (def != wxDragCopy && def != wxDragMove)
			return wxDragError;

		wxString subdir;
		int flags;
		int hit = m_pLocalListView->HitTest(wxPoint(x, y), flags, 0);
		if (hit != -1 && (flags & wxLIST_HITTEST_ONITEM))
		{
			const CLocalListView::t_fileData* const data = m_pLocalListView->GetData(hit);
			if (data && data->dir)
				subdir = data->name;
		}

		wxString dir;
		if (subdir != _T(""))
		{
			dir = CState::Canonicalize(m_pLocalListView->m_dir, subdir);
			if (dir == _T(""))
				return wxDragError;
		}
		else
			dir = m_pLocalListView->m_dir;

		if (!CState::LocalDirIsWriteable(dir))
			return wxDragError;

		if (!GetData())
			return wxDragError;

		if (m_pDataObject->GetReceivedFormat() == m_pFileDataObject->GetFormat())
			m_pLocalListView->m_pState->HandleDroppedFiles(m_pFileDataObject, dir, def == wxDragCopy);
		else
		{
			if (m_pRemoteDataObject->GetProcessId() != (int)wxGetProcessId())
			{
				wxMessageBox(_("Drag&drop between different instances of FileZilla has not been implemented yet."));
				return wxDragNone;
			}

			if (!m_pLocalListView->m_pState->GetServer() || m_pRemoteDataObject->GetServer() != *m_pLocalListView->m_pState->GetServer())
			{
				wxMessageBox(_("Drag&drop between different servers has not been implemented yet."));
				return wxDragNone;
			}

			if (!m_pLocalListView->m_pState->DownloadDroppedFiles(m_pRemoteDataObject, dir))
				return wxDragNone;
		}

		return def;
	}
Ejemplo n.º 28
0
	virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def)
	{
		if (def == wxDragError ||
			def == wxDragNone ||
			def == wxDragCancel)
			return def;

		wxTreeItemId hit = GetHit(wxPoint(x, y));
		if (!hit)
			return wxDragNone;

		CServerPath path = m_pRemoteTreeView->GetPathFromItem(hit);
		if (path.empty())
			return wxDragNone;

		if (!GetData())
			return wxDragError;

		CDragDropManager* pDragDropManager = CDragDropManager::Get();
		if (pDragDropManager)
			pDragDropManager->pDropTarget = m_pRemoteTreeView;

		if (m_pDataObject->GetReceivedFormat() == m_pFileDataObject->GetFormat())
			m_pRemoteTreeView->m_pState->UploadDroppedFiles(m_pFileDataObject, path, false);
		else
		{
			if (m_pRemoteDataObject->GetProcessId() != (int)wxGetProcessId())
			{
				wxMessageBoxEx(_("Drag&drop between different instances of FileZilla has not been implemented yet."));
				return wxDragNone;
			}

			if (!m_pRemoteTreeView->m_pState->GetServer() || !m_pRemoteDataObject->GetServer().EqualsNoPass(*m_pRemoteTreeView->m_pState->GetServer()))
			{
				wxMessageBoxEx(_("Drag&drop between different servers has not been implemented yet."));
				return wxDragNone;
			}

			// Make sure path path is valid
			if (path == m_pRemoteDataObject->GetServerPath())
			{
				wxMessageBoxEx(_("Source and path of the drop operation are identical"));
				return wxDragNone;
			}

			const std::list<CRemoteDataObject::t_fileInfo>& files = m_pRemoteDataObject->GetFiles();
			for (std::list<CRemoteDataObject::t_fileInfo>::const_iterator iter = files.begin(); iter != files.end(); ++iter)
			{
				const CRemoteDataObject::t_fileInfo& info = *iter;
				if (info.dir)
				{
					CServerPath dir = m_pRemoteDataObject->GetServerPath();
					dir.AddSegment(info.name);
					if (dir == path)
						return wxDragNone;
					else if (dir.IsParentOf(path, false))
					{
						wxMessageBoxEx(_("A directory cannot be dragged into one of its subdirectories."));
						return wxDragNone;
					}
				}
			}

			for (std::list<CRemoteDataObject::t_fileInfo>::const_iterator iter = files.begin(); iter != files.end(); ++iter)
			{
				const CRemoteDataObject::t_fileInfo& info = *iter;
				m_pRemoteTreeView->m_pState->m_pCommandQueue->ProcessCommand(
					new CRenameCommand(m_pRemoteDataObject->GetServerPath(), info.name, path, info.name)
					);
			}

			return wxDragNone;
		}

		return def;
	}
Ejemplo n.º 29
0
bool wxLuaDebuggerCServer::StopServer()
{
    // NO checks, can always call stop server

    // Set the shutdown flag
    m_shutdown = true;

    // try to nicely stop the socket if it exists
    if (m_acceptedSocket)
    {
        Reset();
        wxMilliSleep(500);
    }

    // close the session socket, but first NULL it so we won't try to use it
    //m_acceptSockCritSect.Enter();
    wxLuaSocket *acceptedSocket = m_acceptedSocket;
    //m_acceptedSocket = NULL;
    //m_acceptSockCritSect.Leave();

    if (acceptedSocket != NULL)
    {
        if (!acceptedSocket->Shutdown(SD_BOTH))
        {
            wxLuaDebuggerEvent debugEvent(wxEVT_WXLUA_DEBUGGER_ERROR, this);
            debugEvent.SetMessage(acceptedSocket->GetErrorMsg(true));
            AddPendingEvent(debugEvent);
        }

        wxMilliSleep(500);
        //m_acceptedSocket = NULL;
        //delete acceptedSocket;
    }

    // close the server socket, if accepted socket created it will already
    // have been deleted
    if (m_serverSocket != NULL)
    {
        wxLuaSocket *serverSocket = m_serverSocket;
        m_serverSocket = NULL;

        // close the server socket by connecting to the socket, thus
        // completing the 'accept'. If a client has not connected, this
        // code will satisfy the accept the m_shutdown flag will be set
        // so the thread will not loop and instead will just destroy the
        // session socket object and return.
        wxLuaSocket closeSocket;
        closeSocket.m_name = wxString::Format(wxT("wxLuaDebuggerCServer closeSocket (%ld)"), (long)wxGetProcessId());

        if (!closeSocket.Connect(GetNetworkName(),  m_port_number) ||
            !closeSocket.Shutdown(SD_BOTH))
        {
            wxLuaDebuggerEvent debugEvent(wxEVT_WXLUA_DEBUGGER_ERROR, this);
            debugEvent.SetMessage(serverSocket->GetErrorMsg(true));
            AddPendingEvent(debugEvent);
        }

        wxMilliSleep(100);

        delete serverSocket;
    }

    // One of the above two operations terminates the thread. Wait for it to stop.
    if ((m_pThread != NULL) && m_pThread->IsRunning())
        m_pThread->Wait();

    delete m_pThread;
    m_pThread = NULL;

    return true;
}
Ejemplo n.º 30
0
void
mux_dialog::run() {
    auto &arg_list = static_cast<mmg_dialog *>(GetParent())->get_command_line_args();

    opt_file_name.Printf(wxT("%smmg-mkvmerge-options-%d-%d"), get_temp_dir().c_str(), (int)wxGetProcessId(), (int)wxGetUTCTime());
    try {
        const unsigned char utf8_bom[3] = {0xef, 0xbb, 0xbf};
        wxFile opt_file{opt_file_name, wxFile::write};
        opt_file.Write(utf8_bom, 3);

        for (size_t i = 1; i < arg_list.Count(); i++) {
            if (arg_list[i].IsEmpty())
                opt_file.Write(wxT("#EMPTY#"));
            else {
                auto arg_utf8 = escape(to_utf8(arg_list[i]));
                opt_file.Write(arg_utf8.c_str(), arg_utf8.length());
            }
            opt_file.Write(wxT("\n"));
        }
    } catch (mtx::mm_io::exception &ex) {
        wxString error;
        error.Printf(Z("Could not create a temporary file for mkvmerge's command line option called '%s' (error code %d, %s)."), opt_file_name.c_str(), errno, wxUCS(ex.error()));
        wxMessageBox(error, Z("File creation failed"), wxOK | wxCENTER | wxICON_ERROR);
        throw 0;
    }

#if defined(SYS_WINDOWS)
    if (get_windows_version() >= WINDOWS_VERSION_7) {
        m_taskbar_progress = new taskbar_progress_c(mdlg);
        m_taskbar_progress->set_state(TBPF_NORMAL);
        m_taskbar_progress->set_value(0, 100);
    }
#endif  // SYS_WINDOWS

    update_label(Z("Muxing in progress."));

    m_start_time                 = get_current_time_millis();
    m_next_remaining_time_update = m_start_time + 8000;

    m_process                    = new mux_process{this};
    m_pid                        = wxExecute(wxString::Format(wxT("\"%s\" \"@%s\""), arg_list[0].c_str(), opt_file_name.c_str()), wxEXEC_ASYNC, m_process);

    if (0 == m_pid) {
        wxCommandEvent evt(mux_process::event, mux_process::process_terminated);
        evt.SetInt(2);
        wxPostEvent(this, evt);

    } else {
        m_read_input_timer.SetOwner(this, ID_T_READ_INPUT);
        m_read_input_timer.Start(100);
    }

    ShowModal();
}