void change_param_sfo_version(char *file) { FILE *fp; fp = fopen(file, "rb"); if (fp != NULL) { unsigned len, pos, str; unsigned char *mem = NULL; fseek(fp, 0, SEEK_END); len = ftell(fp); mem = (unsigned char *) malloc(len + 16); if (!mem) { fclose(fp); return; } memset(mem, 0, len + 16); fseek(fp, 0, SEEK_SET); fread((void *) mem, len, 1, fp); fclose(fp); str = (mem[8] + (mem[9] << 8)); pos = (mem[0xc] + (mem[0xd] << 8)); int indx = 0; while (str < len) { if (mem[str] == 0) break; if (!strcmp((char *) &mem[str], "PS3_SYSTEM_VER")) { double ver; ver = strtod((char *) &mem[pos], NULL); if (ver > 3.41) { char msg[128]; snprintf(msg, sizeof(msg), "This game requires PS3_SYSTEM_VER %.2f\nDo you want to try fixing PARAM.SFO by forcing 3.41 version?", ver); dialog_ret = 0; cellMsgDialogOpen2(type_dialog_yes_no, msg, dialog_fun1, (void *) 0x0000aaaa, NULL); wait_dialog(); if (dialog_ret == 1) { memcpy(&mem[pos], "03.410", 6); fp = fopen(file, "wb"); fwrite(mem, len, 1, fp); fclose(fp); } } break; } while (mem[str]) str++; str++; pos += (mem[0x1c + indx] + (mem[0x1d + indx] << 8)); indx += 16; } if (mem) free(mem); } }
void SpellChecker::check() { setDisabled(true); QProgressDialog wait_dialog(tr("Checking spelling..."), tr("Cancel"), 0, m_document->document()->characterCount(), this); wait_dialog.setWindowTitle(tr("Please wait")); wait_dialog.setValue(0); wait_dialog.setWindowModality(Qt::WindowModal); forever { // Update wait dialog wait_dialog.setValue(m_cursor.position()); if (wait_dialog.wasCanceled()) { m_document->setTextCursor(m_start_cursor); reject(); } // Check current line QTextBlock block = m_cursor.block(); QStringRef word = m_dictionary->check(block.text(), m_cursor.position() - block.position()); if (word.isNull()) { if (block.next().isValid()) { m_cursor.movePosition(QTextCursor::NextBlock); continue; } else { break; } } // Select misspelled word m_cursor.setPosition(word.position() + block.position()); m_cursor.setPosition(m_cursor.position() + word.length(), QTextCursor::KeepAnchor); m_word = m_cursor.selectedText(); if (!m_ignored.contains(m_word)) { wait_dialog.close(); setEnabled(true); // Show misspelled word in context QTextCursor cursor = m_cursor; cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::MoveAnchor, 10); int end = m_cursor.position() - cursor.position(); int start = end - m_word.length(); cursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor, 21); QString context = cursor.selectedText(); context.insert(end, "</span>"); context.insert(start, "<span style=\"color: red;\">"); context.replace("\n", "</p><p>"); context.replace("\t", "<span style=\"white-space: pre;\">\t</span>"); context = "<p>" + context + "</p>"; m_context->setHtml(context); // Show suggestions m_suggestion->clear(); m_suggestions->clear(); QStringList words = m_dictionary->suggestions(m_word); if (!words.isEmpty()) { foreach (const QString& word, words) { m_suggestions->addItem(word); } m_suggestions->setCurrentRow(0); }
void SpellChecker::check() { setDisabled(true); QProgressDialog wait_dialog(tr("Checking spelling..."), tr("Cancel"), 0, m_total_blocks, this); wait_dialog.setWindowTitle(tr("Please wait")); wait_dialog.setValue(0); wait_dialog.setWindowModality(Qt::WindowModal); bool canceled = false; forever { // Update wait dialog wait_dialog.setValue(m_checked_blocks); if (wait_dialog.wasCanceled()) { canceled = true; break; } // Check current line QTextBlock block = m_cursor.block(); QStringRef word = m_dictionary.check(block.text(), m_cursor.position() - block.position()); if (word.isNull()) { if (block.next().isValid()) { m_cursor.movePosition(QTextCursor::NextBlock); ++m_checked_blocks; if (m_checked_blocks < m_total_blocks) { continue; } else { break; } } else if (m_loop_available) { wait_dialog.reset(); if (QMessageBox::question(this, QString(), tr("Continue checking at beginning of file?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes) { m_loop_available = false; m_cursor.movePosition(QTextCursor::Start); wait_dialog.setRange(0, m_total_blocks); continue; } else { canceled = true; break; } } else { break; } } // Select misspelled word m_cursor.setPosition(word.position() + block.position()); m_cursor.setPosition(m_cursor.position() + word.length(), QTextCursor::KeepAnchor); m_word = m_cursor.selectedText(); if (!m_ignored.contains(m_word)) { wait_dialog.close(); setEnabled(true); // Show misspelled word in context QTextCursor cursor = m_cursor; cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::MoveAnchor, 10); int end = m_cursor.position() - cursor.position(); int start = end - m_word.length(); cursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor, 21); QString context = cursor.selectedText(); context.insert(end, "</span>"); context.insert(start, "<span style=\"color: red;\">"); context.replace("\n", "</p><p>"); context.replace("\t", "<span style=\"white-space: pre;\">\t</span>"); context = "<p>" + context + "</p>"; m_context->setHtml(context); // Show suggestions m_suggestion->clear(); m_suggestions->clear(); QStringList words = m_dictionary.suggestions(m_word); if (!words.isEmpty()) { foreach (const QString& word, words) { m_suggestions->addItem(word); } m_suggestions->setCurrentRow(0); }
int execute(char *exname, char *inname, char *outname, double t, int max_mem) { STARTUPINFO si; PROCESS_INFORMATION pi; int ifsuccess = EXE_RESULT_OK; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); ZeroMemory(&pi, sizeof(pi)); setstartupinfo(&si, inname, outname); if(!CreateProcess( NULL, // No module name (use command line). TEXT(exname), // Command line. NULL, // Process handle not inheritable. NULL, // Thread handle not inheritable. TRUE, // Set handle inheritance to FALSE. 0, // No creation flags. NULL, // Use parent's environment block. NULL, // Use parent's starting directory. &si, // Pointer to STARTUPINFO structure. &pi)) // Pointer to PROCESS_INFORMATION structure. { //printf( "CreateProcess failed (%d).\n", GetLastError() ); } //fprintf(stderr,"Process ID: %ld\n",pi.dwProcessId); //fprintf(stderr,"time limit = %d\n",t); SetProcessWorkingSetSize(pi.hProcess, 1, max_mem); // checking memory usage // wait 0.1 sec before checking mem usage Sleep(INITIAL_WAIT_FOR_MEM_CHECK); if(!check_memory_usage(pi.dwProcessId,max_mem)) { // using too much memory printf("memory exceeded (beginning)\n"); PrintMemoryInfo(pi.dwProcessId); ifsuccess = EXE_RESULT_MEMORY; } if((ifsuccess == EXE_RESULT_MEMORY) || (WaitForSingleObject(pi.hProcess, (int)(t*1000) + 1 - INITIAL_WAIT_FOR_MEM_CHECK)==WAIT_TIMEOUT)) { // need to kill... HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pi.dwProcessId); if(hProcess != NULL) { fprintf(stderr,"killing pid: %ld\n",pi.dwProcessId); TerminateProcess(hProcess, 0); wait_dialog(); } else { DWORD dwNtvdmId = get_ntvdm_pid(); fprintf(stderr,"killing (ntvdm) pid: %ld\n",dwNtvdmId); if(dwNtvdmId!=0) { hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwNtvdmId); TerminateProcess(hProcess, 0); } else { fprintf(stderr,"killing process error\n"); } if(get_ntvdm_pid()!=0) { fprintf(stderr,"killing error, ntvdm.exe still remains;"); fprintf(stderr,"please MANUALLY kill it."); fflush(stderr); do { Sleep(1000); } while(get_ntvdm_pid()!=0); fprintf(stderr,"... done\n"); wait_dialog(); } } if(ifsuccess != EXE_RESULT_MEMORY) ifsuccess = EXE_RESULT_TIMEOUT; } if((ifsuccess==EXE_RESULT_OK) && (!check_memory_usage(pi.dwProcessId,max_mem))) { // using too much memory ifsuccess = EXE_RESULT_MEMORY; } wait_dialog(); if(si.hStdInput!=NULL) CloseHandle(si.hStdInput); if(si.hStdOutput!=NULL) CloseHandle(si.hStdOutput); return ifsuccess; }