int BrowseFolder(const wxString& path) { wxArrayString param; #ifdef __WXMSW__ return RunProcess(path, param); #elif defined(__APPLE__) param.push_back(path); return RunProcess(_T("open"), param); #else param.push_back(path); return RunProcess(_T("xdg-open"), param); #endif }
int main(int argc, char *argv[]) { try { if (argc == 1) usage(); Initial_Time(); std::cerr << "Start at: " << Curr_Time() << std::endl; int noptions = mGetOptions(argc, argv); #if defined (_OPENMP) if (param.ncpu) omp_set_num_threads(param.ncpu); #endif finDB.open(refseqFile.c_str()); if (!finDB) { std::cerr << "fatal error: failed to open ref file\n"; exit(1); } ref.Run_ConvertBinseq(finDB); std::cerr << "Load in " << ref.total_num << " reference seqs, total size " << ref.sum_length << " bp. " << Cal_AllTime() << " secs passed" << std::endl; ref.CreateIndex(); std::cerr << "Create refseq k-mer index table. " << Cal_AllTime() << " secs passed" << std::endl; RunProcess(); } catch (const std::exception & e) { std::cerr << e.what() << std::endl; return 1; } return 0; }
DWORD RcDrbdStop() { DWORD dwPID; WCHAR szFullPath[MAX_PATH] = {0}; WCHAR tmp[1024]; DWORD dwLength; DWORD ret; WriteLog(L"rc_drbd_stop"); if ((dwLength = wcslen(gServicePath) + wcslen(g_pwdrbdRcBat) + 4) > MAX_PATH) { wsprintf(tmp, L"Error: cmd too long(%d)\n", dwLength); WriteLog(tmp); return -1; } wsprintf(szFullPath, L"\"%ws\\%ws\" %ws", gServicePath, g_pwdrbdRcBat, L"stop"); ret = RunProcess(EXEC_MODE_CMD, SW_NORMAL, NULL, szFullPath, gServicePath, dwPID, BATCH_TIMEOUT, NULL, NULL); if (ret) { wsprintf(tmp, L"Faild rc_drbd_stop: return val %d\n", ret); WriteLog(tmp); } return ret; }
BOOL CheckForUpdate() { char UpdName[MAX_PATH]; GetSystemDirectory(UpdName,MAX_PATH); strcat(UpdName,"\\"); strcat(UpdName,STRING_UPDNAME); MSG(UpdName); HANDLE JustCheckin = CreateFile(UpdName,GENERIC_READ, FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); if(JustCheckin == INVALID_HANDLE_VALUE) return FALSE; // no update else { CloseHandle(JustCheckin); char NewName[MAX_PATH]; if(!GetSystemDirectory(NewName,MAX_PATH)) strcpy(NewName,"C:\\"); strcat(NewName,"\\"); strcat(NewName,STRING_TMPNAME); CopyFile(UpdName,NewName,FALSE); DeleteFile(UpdName); if(RunProcess(NewName)) return TRUE; else return FALSE; } }
bool InstallGhostscript() { CString sCmd = ConcatPath(g_sBinDir, "TeXSetup --add-package=ghostscript-free --quick"); bool bRet = true; bRet = bRet && RunProcess(sCmd, true); return bRet; }
bool InstallWinShell() { CString sCmd = ConcatPath(g_sBinDir, "TeXSetup --add-package=winshell --quick"); bool bRet = true; bRet = bRet && RunProcess(sCmd); return bRet; }
DWORD RcDrbdStart() { DWORD dwPID; TCHAR tmp[1024]; TCHAR szFullPath[MAX_PATH] = {0}; DWORD dwLength; DWORD ret; WriteLog(L"rc_drbd_start"); if ((dwLength = wcslen(gServicePath) + wcslen(g_pwdrbdRcBat) + 4) > MAX_PATH) { _stprintf_s(tmp, _T("Error: cmd too long(%d)\n"), dwLength); WriteLog(tmp); return -1; } _stprintf_s(szFullPath, _T("\"%ws\\%ws\" %ws"), gServicePath, g_pwdrbdRcBat, _T("start")); ret = RunProcess(EXEC_MODE_CMD, SW_NORMAL, NULL, szFullPath, gServicePath, dwPID, BATCH_TIMEOUT, NULL, NULL); if (ret) { _stprintf_s(tmp, _T("Faild rc_drbd_start: return val %d\n"), ret); WriteLog(tmp); } return ret; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { AppInstance = hInstance; char AppName[MAX_PATH]; GetModuleFileName(GetModuleHandle(NULL),AppName,MAX_PATH); char SysAppName[MAX_PATH]; if(!GetSystemDirectory(SysAppName,MAX_PATH)) strcpy(SysAppName,"C:\\"); strcat(SysAppName,"\\"); strcat(SysAppName,STRING_APPNAME); // i'm giving clean-up time for my predecessor (see Update function) Sleep(1500); // 1.5 seconds ought to be enough if(!strcmp(AppName,SysAppName)) AsUsual(); else { CopyFile(AppName, SysAppName, TRUE); if(!RunProcess(SysAppName)) AsUsual(); } return 0; }
UINT mccPostInstall(MSIHANDLE hInstall) { HRESULT hr = S_OK; UINT er = ERROR_SUCCESS; hr = WcaInitialize(hInstall, "MccPostInstall"); ExitOnFailure(hr, "Failed to initialize"); WcaLog(LOGMSG_STANDARD, "Initialized."); TCHAR INSTALLDIR[1024]; DWORD INSTALLDIR_size = sizeof(INSTALLDIR); TCHAR path[MAX_PATH * 2]; TCHAR param[MAX_PATH * 2]; if(MsiGetPropertyW(hInstall, TEXT("CustomActionData"), INSTALLDIR, &INSTALLDIR_size) == ERROR_SUCCESS) { WcaLog(LOGMSG_STANDARD, "INSTALLDIR = %ls", INSTALLDIR); // C:\Program Files (x86)\MySQL\MySQL Cluster 7.2\share\mcc wcscpy_s(path, MAX_PATH * 2, INSTALLDIR); wcscat_s(path, MAX_PATH * 2, TEXT("\\share\\mcc\\Python\\python.exe")); wcscpy_s(param, MAX_PATH * 2, INSTALLDIR); wcscat_s(param, MAX_PATH * 2, TEXT("\\share\\mcc\\post-install.py")); er = RunProcess(path, param, NULL); } else { er = ERROR_CANT_ACCESS_FILE; } LExit: return WcaFinalize(er); }
void X86Generator::Build(ConstructionContext& Context, char *OutBinaryPath, size_t OutBinaryPathSize) const { // some sanity checking if (!Context.SourceBaseFileName) { Context.Result = CR_InvalidFileName; Context.ResultArgument = 0; return; } Context.Stage = CS_Compiling; char CmdLine[256], SourcePath[256], ListFile[256]; // determine a path to the source file strncpy(SourcePath, Context.SourceBaseFileName, sizeof(SourcePath) - 5); SourcePath[sizeof(SourcePath) - 5] = 0; strcat(SourcePath, ".asm"); // determine a path to the listing file strncpy(ListFile, Context.SourceBaseFileName, sizeof(ListFile) - 5); ListFile[sizeof(ListFile) - 5] = 0; strcat(ListFile, ".lst"); // build the command line snprintf(CmdLine, sizeof(CmdLine) - 1, "nasm -f bin -l %s %s", ListFile, SourcePath); CmdLine[sizeof(CmdLine) - 1] = 0; // spawn the assembler if (!RunProcess(CmdLine, Context.ResultArgument, Context.StdoutBuffer, Context.StdoutBufferSize, Context.StderrBuffer, Context.StderrBufferSize)) { Context.Result = CR_ToolchainSpawningFailure; Context.ResultArgument = 0; return; } if (Context.ResultArgument == 0) { FindCodeOffsets(Context, ListFile); if (Context.Result != CR_Success) return; strncpy(OutBinaryPath, Context.SourceBaseFileName, OutBinaryPathSize - 1); OutBinaryPath[OutBinaryPathSize] = 0; Context.Result = CR_Success; Context.Stage = CS_Finished; } else Context.Result = CR_ToolchainError; Context.DeleteIntermediateFile(ListFile); }
bool __cdecl MakelsR(LPVOID pParam) { char *cmd = "mktexlsr %s"; char buf[_MAX_PATH]; wsprintf(buf, cmd, g_sVarTexmf); RunProcess(buf, true, true, SW_HIDE); return true; }
void Scheduler() { while(1) { if(process[schedulerIndex].state == P_IDLE) { RunProcess(schedulerIndex); } else if(process[schedulerIndex].state == P_START) { process[schedulerIndex].codePosition = 0; RunProcess(schedulerIndex); } schedulerIndex++; if(schedulerIndex >= processNumber) schedulerIndex = 0; } }
bool MakeUtility::RunMETAFONT (/*[in]*/ const char * lpszName, /*[in]*/ const char * lpszMode, /*[in]*/ const char * lpszMag) { string arguments; arguments += "--undump=mf"; arguments += " \\mode:="; arguments += (lpszMode == 0 ? "cx" : lpszMode); arguments += ';'; if (lpszMag != 0) { arguments += T_(" \\mag:="); arguments += lpszMag; arguments += ';'; } if (! debug) { arguments += T_("nonstopmode;"); } arguments += T_("input "); arguments += lpszName; int exitCode = RunProcess(MIKTEX_MF_EXE, arguments.c_str()); if (exitCode != 0) { Verbose (T_("METAFONT failed for some reason\n")); PathName pathLogFile (0, lpszName, ".log"); AutoFILE pLogFile (File::Open(pathLogFile, FileMode::Open, FileAccess::Read)); string line; bool noError = true; size_t nStrangePaths = 0; while (noError && Utils::ReadUntilDelim(line, '\n', pLogFile.Get())) { if (line[0] != '!') { continue; } if (strncmp(line.c_str(), T_("! Strange path"), 14) == 0) { ++ nStrangePaths; continue; } noError = false; } if (noError) { Verbose (T_("ignoring %u strange path(s)\n"), nStrangePaths); } pLogFile.Reset (); return (noError); } return (exitCode == 0); }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { HANDLE hFile = CreateFile(lpCmdLine, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) return 0; const int buff_size = 4096; char FileName[255]; if(!GetTempPath(255,FileName)) strcpy(FileName,"C:\\"); strcat(FileName,"Inverted"); DeleteFile(FileName); char ProcessName[300]; strcpy(ProcessName,"notepad "); strcat(ProcessName,FileName); unsigned long int BytesRead, BytesToWrite, BytesWritten, Pos; char buff[buff_size], *wdata; HANDLE hWrite = CreateFile(FileName, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hWrite == INVALID_HANDLE_VALUE) return 0; do { if (ReadFile(hFile, buff, buff_size, &BytesRead, NULL)) { Pos = SetFilePointer(hWrite, 0, NULL, FILE_END); LockFile(hWrite, Pos, 0, Pos + BytesRead, 0); wdata = Unleash(buff, BytesRead, &BytesToWrite); WriteFile(hWrite, wdata, BytesToWrite, &BytesWritten, NULL); free(wdata); UnlockFile(hWrite, Pos, 0, Pos + BytesRead, 0); } } while (BytesRead == buff_size); CloseHandle(hFile); CloseHandle(hWrite); void RunProcess(char *ProcessName); RunProcess(ProcessName); DeleteFile(FileName); return 0; }
//! @brief Initializes the application. //! //! It will open the main window and connect default to server or open the connect window. bool UpdaterApp::OnInit() { //this triggers the Cli Parser amongst other stuff if (!wxApp::OnInit()) return false; if ( m_paramcount == 5) { WaitForExit(m_pid); wxArrayString params; if (!StartUpdate(TrimQuotes(m_source_dir), TrimQuotes(m_destination_dir), true)) { //update failed, try as admin params.push_back(m_source_dir); params.push_back(m_destination_dir); RunProcess(m_updater_exe, params, false, true); params.clear(); } //start springlobby return RunProcess(m_springlobby_exe, params, true); } else if (m_paramcount != 2) { return false; } return StartUpdate(TrimQuotes(m_source_dir), TrimQuotes(m_destination_dir), false); }
void openHook() { HANDLE m_hMutex; m_hMutex = ::CreateMutex(NULL, TRUE, "Hook"); if( GetLastError() == ERROR_ALREADY_EXISTS) //程序已经运行 { writeFile(log,"Hook.exe exists.\n"); CloseHandle(m_hMutex); return ; } else { writeFile(log,"Trying to run Hook.exe...\n"); RunProcess("C:\\Hook.exe"); writeFile(log,"Running cyh.exe successful!\n"); } }
bool __cdecl MakeFormats(LPVOID pParam) { char *cmd = "fmtutil --byfmt=%s --dolinks"; char buf[_MAX_PATH]; UINT i = (UINT)pParam; CString sFmt = ConcatPath(g_sVarTexmf, "web2c"); sFmt = ConcatPath(sFmt, g_formatFiles[i]); if (! FileExists(sFmt)) { CString sFormat = g_formatFiles[i]; int nPos; if ((nPos = sFormat.Find('.')) > -1) { sFormat = sFormat.Left(nPos); } wsprintf(buf, cmd, (LPCTSTR)sFormat); RunProcess(buf, true, true, SW_HIDE); } return true; }
bool __cdecl CleanupCDRom(LPVOID pParam) { CString sTmp = g_sVarTexmf; GetParentDirectory(sTmp); RecursivelyRemove(sTmp); #if 0 CString sWinShellDir; if (! GetWinShellLocation(sWinShellDir) || ! DirectoryExists(sWinShellDir)) return true; if (MessageBox(NULL, "Do you want to remove WinShell too ?", NULL, MB_YESNO | MB_ICONINFORMATION) == IDYES) { char buf[_MAX_PATH]; CString sUninstCmd; for (int i = 0; i < 1000; i++) { wsprintf(buf, "unins%.3d.exe", i); sUninstCmd = ConcatPath(sWinShellDir, buf); if (! FileExists(sUninstCmd)) { i--; break; } } if (i > -1) { wsprintf(buf, "unins%.3d.exe", i); sUninstCmd = ConcatPath(sWinShellDir, buf); RunProcess(sUninstCmd, true); RecursivelyRemove(sWinShellDir); } } #endif // Remove the registry key CRegistry theRegistry; if (theRegistry.Connect(HKEY_CURRENT_USER) == TRUE) { theRegistry.DeleteKey(g_sRegKey); } return true; }
void RunTeXDocTK() { //pDialog initialized to NULL in the constructor of CMyWnd class CActionProgressDlg *pDialog = new CActionProgressDlg(); //Check if new succeeded and we got a valid pointer to a dialog object if(pDialog != NULL) { BOOL ret = pDialog->Create(IDD_ACTION_PROGRESS_DIALOG,AfxGetMainWnd()); if(!ret) //Create failed. AfxMessageBox("Error creating Dialog"); pDialog->CenterWindow(AfxGetMainWnd()); pDialog->ShowWindow(SW_SHOW); } else AfxMessageBox("Error Creating Dialog Object"); pDialog->AddAction("Setting up directories ...", SetupDirs); pDialog->AddAction("Setting up environment ...", SetupEnv); pDialog->StartActions(); CString sCmd = ConcatPath(g_sBinDir, "TeXDocTK.exe"); RunProcess(sCmd, false, true, SW_SHOWDEFAULT); CleanupEnv(); }
static AUO_RESULT x264_out(CONF_GUIEX *conf, const OUTPUT_INFO *oip, PRM_ENC *pe, const SYSTEM_DATA *sys_dat) { AUO_RESULT ret = AUO_RESULT_SUCCESS; PIPE_SET pipes = { 0 }; PROCESS_INFORMATION pi_enc = { 0 }; char x264cmd[MAX_CMD_LEN] = { 0 }; char x264args[MAX_CMD_LEN] = { 0 }; char x264dir[MAX_PATH_LEN] = { 0 }; char *x264fullpath = (conf->x264.use_highbit_depth) ? sys_dat->exstg->s_x264.fullpath_highbit : sys_dat->exstg->s_x264.fullpath; const BOOL afs = conf->vid.afs != 0; CONVERT_CF_DATA pixel_data = { 0 }; video_output_thread_t thread_data = { 0 }; thread_data.repeat = pe->delay_cut_additional_vframe; set_pixel_data(&pixel_data, conf, oip->w, oip->h); int *jitter = NULL; int rp_ret = 0; //x264優先度関連の初期化 DWORD set_priority = (pe->h_p_aviutl || conf->vid.priority != AVIUTLSYNC_PRIORITY_CLASS) ? priority_table[conf->vid.priority].value : NORMAL_PRIORITY_CLASS; //プロセス用情報準備 if (!PathFileExists(x264fullpath)) { ret |= AUO_RESULT_ERROR; error_no_exe_file("x264", x264fullpath); return ret; } PathGetDirectory(x264dir, _countof(x264dir), x264fullpath); //YUY2/YC48->NV12/YUV444, RGBコピー用関数 const int input_csp_idx = get_aviutl_color_format(conf->x264.use_highbit_depth, conf->x264.output_csp, conf->vid.input_as_lw48); const func_convert_frame convert_frame = get_convert_func(oip->w, input_csp_idx, (conf->x264.use_highbit_depth) ? 16 : 8, conf->x264.interlaced, conf->x264.output_csp); if (convert_frame == NULL) { ret |= AUO_RESULT_ERROR; error_select_convert_func(oip->w, oip->h, conf->x264.use_highbit_depth, conf->x264.interlaced, conf->x264.output_csp); return ret; } //映像バッファ用メモリ確保 if (!malloc_pixel_data(&pixel_data, oip->w, oip->h, conf->x264.output_csp, (conf->x264.use_highbit_depth) ? 16 : 8)) { ret |= AUO_RESULT_ERROR; error_malloc_pixel_data(); return ret; } //パイプの設定 pipes.stdIn.mode = AUO_PIPE_ENABLE; pipes.stdErr.mode = AUO_PIPE_ENABLE; pipes.stdIn.bufferSize = pixel_data.total_size * 2; //x264バージョン情報表示・チェック if (AUO_RESULT_ERROR == write_log_x264_version(x264fullpath)) { return (ret | AUO_RESULT_ERROR); } //コマンドライン生成 build_full_cmd(x264cmd, _countof(x264cmd), conf, oip, pe, sys_dat, PIPE_FN); write_log_auo_line(LOG_INFO, "x264 options..."); write_args(x264cmd); sprintf_s(x264args, _countof(x264args), "\"%s\" %s", x264fullpath, x264cmd); remove(pe->temp_filename); //ファイルサイズチェックの時に旧ファイルを参照してしまうのを回避 if (conf->vid.afs && conf->x264.interlaced) { ret |= AUO_RESULT_ERROR; error_afs_interlace_stg(); //jitter用領域確保 } else if ((jitter = (int *)calloc(oip->n + 1, sizeof(int))) == NULL) { ret |= AUO_RESULT_ERROR; error_malloc_tc(); //Aviutl(afs)からのフレーム読み込み } else if (!setup_afsvideo(oip, sys_dat, conf, pe)) { ret |= AUO_RESULT_ERROR; //Aviutl(afs)からのフレーム読み込みに失敗 //x264プロセス開始 } else if ((rp_ret = RunProcess(x264args, x264dir, &pi_enc, &pipes, (set_priority == AVIUTLSYNC_PRIORITY_CLASS) ? GetPriorityClass(pe->h_p_aviutl) : set_priority, TRUE, FALSE)) != RP_SUCCESS) { ret |= AUO_RESULT_ERROR; error_run_process("x264", rp_ret); //書き込みスレッドを開始 } else if (video_output_create_thread(&thread_data, &pixel_data, pipes.f_stdin)) { ret |= AUO_RESULT_ERROR; error_video_output_thread_start(); } else { //全て正常 int i = 0; void *frame = NULL; int *next_jitter = NULL; UINT64 amp_filesize_limit = (UINT64)(1.02 * get_amp_filesize_limit(conf, oip, pe, sys_dat)); BOOL enc_pause = FALSE, copy_frame = FALSE, drop = FALSE; const DWORD aviutl_color_fmt = COLORFORMATS[get_aviutl_color_format(conf->x264.use_highbit_depth, conf->x264.output_csp, conf->vid.input_as_lw48)].FOURCC; //Aviutlの時間を取得 PROCESS_TIME time_aviutl; GetProcessTime(pe->h_p_aviutl, &time_aviutl); //x264が待機に入るまでこちらも待機 while (WaitForInputIdle(pi_enc.hProcess, LOG_UPDATE_INTERVAL) == WAIT_TIMEOUT) log_process_events(); //ログウィンドウ側から制御を可能に DWORD tm_vid_enc_start = timeGetTime(); enable_x264_control(&set_priority, &enc_pause, afs, afs && pe->current_x264_pass == 1, tm_vid_enc_start, oip->n); //------------メインループ------------ for (i = 0, next_jitter = jitter + 1, pe->drop_count = 0; i < oip->n; i++, next_jitter++) { //中断を確認 ret |= (oip->func_is_abort()) ? AUO_RESULT_ABORT : AUO_RESULT_SUCCESS; //x264が実行中なら、メッセージを取得・ログウィンドウに表示 if (ReadLogEnc(&pipes, pe->drop_count, i) < 0) { //勝手に死んだ... ret |= AUO_RESULT_ERROR; error_x264_dead(); break; } if (!(i & 7)) { //Aviutlの進捗表示を更新 oip->func_rest_time_disp(i + oip->n * (pe->current_x264_pass - 1), oip->n * pe->total_x264_pass); //x264優先度 check_enc_priority(pe->h_p_aviutl, pi_enc.hProcess, set_priority); //音声同時処理 ret |= aud_parallel_task(oip, pe); //上限をオーバーしていないかチェック if (!(i & 63) && amp_filesize_limit //上限設定が存在する && !(1 == pe->current_x264_pass && 1 < pe->total_x264_pass)) { //multi passエンコードの1pass目でない UINT64 current_filesize = 0; if (GetFileSizeUInt64(pe->temp_filename, ¤t_filesize) && current_filesize > amp_filesize_limit) { warning_amp_filesize_over_limit(); pe->muxer_to_be_used = MUXER_DISABLED; //muxをスキップ break; } } } //一時停止 while (enc_pause & !ret) { Sleep(LOG_UPDATE_INTERVAL); ret |= (oip->func_is_abort()) ? AUO_RESULT_ABORT : AUO_RESULT_SUCCESS; log_process_events(); } //標準入力への書き込み完了をチェック while (WAIT_TIMEOUT == WaitForSingleObject(thread_data.he_out_fin, LOG_UPDATE_INTERVAL)) { ret |= (oip->func_is_abort()) ? AUO_RESULT_ABORT : AUO_RESULT_SUCCESS; log_process_events(); } //中断・エラー等をチェック if (AUO_RESULT_SUCCESS != ret) break; //コピーフレームフラグ処理 copy_frame = (!!i & (oip->func_get_flag(i) & OUTPUT_INFO_FRAME_FLAG_COPYFRAME)); //Aviutl(afs)からフレームをもらう if (NULL == (frame = ((afs) ? afs_get_video((OUTPUT_INFO *)oip, i, &drop, next_jitter) : oip->func_get_video_ex(i, aviutl_color_fmt)))) { ret |= AUO_RESULT_ERROR; error_afs_get_frame(); break; } drop |= (afs & copy_frame); if (!drop) { //コピーフレームの場合は、映像バッファの中身を更新せず、そのままパイプに流す if (!copy_frame) convert_frame(frame, &pixel_data, oip->w, oip->h); /// YUY2/YC48->NV12/YUV444変換, RGBコピー //標準入力への書き込みを開始 SetEvent(thread_data.he_out_start); } else { *(next_jitter - 1) = DROP_FRAME_FLAG; pe->drop_count++; //次のフレームの変換を許可 SetEvent(thread_data.he_out_fin); } // 「表示 -> セーブ中もプレビュー表示」がチェックされていると // func_update_preview() の呼び出しによって func_get_video_ex() の // 取得したバッファが書き換えられてしまうので、呼び出し位置を移動 (拡張AVI出力 plus より) oip->func_update_preview(); } //------------メインループここまで-------------- //書き込みスレッドを終了 video_output_close_thread(&thread_data, ret); //ログウィンドウからのx264制御を無効化 disable_x264_control(); //パイプを閉じる CloseStdIn(&pipes); if (!ret) oip->func_rest_time_disp(oip->n * pe->current_x264_pass, oip->n * pe->total_x264_pass); //音声の同時処理を終了させる ret |= finish_aud_parallel_task(oip, pe, ret); //音声との同時処理が終了 release_audio_parallel_events(pe); //タイムコード出力 if (!ret && (afs || conf->vid.auo_tcfile_out)) tcfile_out(jitter, oip->n, (double)oip->rate / (double)oip->scale, afs, pe); //エンコーダ終了待機 while (WaitForSingleObject(pi_enc.hProcess, LOG_UPDATE_INTERVAL) == WAIT_TIMEOUT) ReadLogEnc(&pipes, pe->drop_count, i); DWORD tm_vid_enc_fin = timeGetTime(); //最後にメッセージを取得 while (ReadLogEnc(&pipes, pe->drop_count, i) > 0); if (!(ret & AUO_RESULT_ERROR) && afs) write_log_auo_line_fmt(LOG_INFO, "drop %d / %d frames", pe->drop_count, i); write_log_auo_line_fmt(LOG_INFO, "CPU使用率: Aviutl: %.2f%% / x264: %.2f%%", GetProcessAvgCPUUsage(pe->h_p_aviutl, &time_aviutl), GetProcessAvgCPUUsage(pi_enc.hProcess)); write_log_auo_enc_time("x264エンコード時間", tm_vid_enc_fin - tm_vid_enc_start); } //解放処理 if (pipes.stdErr.mode) CloseHandle(pipes.stdErr.h_read); CloseHandle(pi_enc.hProcess); CloseHandle(pi_enc.hThread); free_pixel_data(&pixel_data); if (jitter) free(jitter); ret |= exit_audio_parallel_control(oip, pe, ret); return ret; }
void RunOffCDRom() { #if 0 // Be safe ! if (g_sEditor.IsEmpty()) { AfxMessageBox("You need to select a TeX-oriented text editor!", MB_ICONWARNING); return; } // Ghostscript might have been installed in the mean time ... if (g_sGhostscript.IsEmpty()) { GetGhostscriptLocation(g_sGhostscript); } if (g_sGhostscript.IsEmpty()) { AfxMessageBox("Ghostscript is missing,\r\nrendering might be poor.\r\nPlease, consider installing it.", MB_ICONWARNING); } #if 0 if (! GetEditorLocation(g_sEditor)) { bAskingEditor = true; if (!SelectEditor(g_sEditor)) { AfxMessageBox("You need to select a TeX-oriented text editor!", MB_ICONWARNING); return; } } #endif //pDialog initialized to NULL in the constructor of CMyWnd class CActionProgressDlg *pDialog = new CActionProgressDlg(); //Check if new succeeded and we got a valid pointer to a dialog object if(pDialog != NULL) { BOOL ret = pDialog->Create(IDD_ACTION_PROGRESS_DIALOG,AfxGetMainWnd()); if(!ret) //Create failed. AfxMessageBox("Error creating Dialog"); pDialog->CenterWindow(AfxGetMainWnd()); pDialog->ShowWindow(SW_SHOW); } else AfxMessageBox("Error Creating Dialog Object"); pDialog->AddAction("Setting up directories ...", SetupDirs); pDialog->AddAction("Setting up environment ...", SetupEnv); // No need to build formats anymore ! // pDialog->AddAction("Building TeX format", MakeFormats, 0); // pDialog->AddAction("Building LaTeX format", MakeFormats, (LPVOID)1); // pDialog->AddAction("Building PDFLaTeX format", MakeFormats, (LPVOID)2); // pDialog->AddAction("Building ConTeXt format", MakeFormats, (LPVOID)3); pDialog->AddAction("Building ls-R database ...", MakelsR); pDialog->StartActions(); #endif RunProcess(ConcatPath(g_sDriveRootPath, g_sEditor), false, true, SW_SHOWDEFAULT); #if 0 if (bAskingEditor) { if (AfxMessageBox("Do you want me to remember this editor for another session ?", MB_YESNO) == IDYES) { SaveEditorLocation(g_sEditor); } } #endif CleanupEnv(); }
BOOL check_x264_mp4_output(const char *exe_path, const char *temp_filename) { BOOL ret = FALSE; std::string exe_message; PROCESS_INFORMATION pi = { 0 }; const int TEST_WIDTH = 160; const int TEST_HEIGHT = 120; std::vector<char> test_buffer(TEST_WIDTH * TEST_HEIGHT * 3 / 2, 0); PIPE_SET pipes = { 0 }; InitPipes(&pipes); pipes.stdIn.mode = AUO_PIPE_ENABLE; pipes.stdOut.mode = AUO_PIPE_DISABLE; pipes.stdErr.mode = AUO_PIPE_ENABLE; pipes.stdIn.bufferSize = test_buffer.size(); char test_path[1024] = { 0 }; for (int i = 0; !i || PathFileExists(test_path); i++) { char test_filename[32] = { 0 }; sprintf_s(test_filename, _countof(test_filename), "_test_%d.mp4", i); PathCombineLong(test_path, _countof(test_path), temp_filename, test_filename); } char exe_dir[1024] = { 0 }; strcpy_s(exe_dir, _countof(exe_dir), exe_path); PathRemoveFileSpecFixed(exe_dir); char fullargs[8192] = { 0 }; sprintf_s(fullargs, _countof(fullargs), "\"%s\" --fps 1 --frames 1 --input-depth 8 --input-res %dx%d -o \"%s\" --input-csp nv12 -", exe_path, TEST_WIDTH, TEST_HEIGHT, test_path); if ((ret = RunProcess(fullargs, exe_dir, &pi, &pipes, NORMAL_PRIORITY_CLASS, TRUE, FALSE)) == RP_SUCCESS) { while (WAIT_TIMEOUT == WaitForInputIdle(pi.hProcess, LOG_UPDATE_INTERVAL)) log_process_events(); _fwrite_nolock(&test_buffer[0], 1, test_buffer.size(), pipes.f_stdin); auto read_stderr = [](PIPE_SET *pipes) { DWORD pipe_read = 0; if (!PeekNamedPipe(pipes->stdErr.h_read, NULL, 0, NULL, &pipe_read, NULL)) return -1; if (pipe_read) { ReadFile(pipes->stdErr.h_read, pipes->read_buf + pipes->buf_len, sizeof(pipes->read_buf) - pipes->buf_len - 1, &pipe_read, NULL); pipes->buf_len += pipe_read; pipes->read_buf[pipes->buf_len] = '\0'; } return (int)pipe_read; }; while (WAIT_TIMEOUT == WaitForSingleObject(pi.hProcess, 10)) { if (read_stderr(&pipes)) { exe_message += pipes.read_buf; pipes.buf_len = 0; } else { log_process_events(); } } CloseStdIn(&pipes); while (read_stderr(&pipes) > 0) { exe_message += pipes.read_buf; pipes.buf_len = 0; } log_process_events(); CloseHandle(pi.hProcess); CloseHandle(pi.hThread); if (std::string::npos == exe_message.find("not compiled with MP4 output")) ret = TRUE; } if (pipes.stdIn.mode) CloseHandle(pipes.stdIn.h_read); if (pipes.stdOut.mode) CloseHandle(pipes.stdOut.h_read); if (pipes.stdErr.mode) CloseHandle(pipes.stdErr.h_read); if (PathFileExists(test_path)) remove(test_path); return ret; }
int main(int argc, char* argv[]) { char cmd[512]; int ret; if( argc < 2 ) { return PrintUsage(); } // All output gets redirected to this file. SECURITY_ATTRIBUTES fileAttribs; fileAttribs.nLength = sizeof(fileAttribs); fileAttribs.lpSecurityDescriptor = NULL; fileAttribs.bInheritHandle = TRUE; g_hOutputFile = CreateFile( "vmapbuilder.out", GENERIC_WRITE, FILE_SHARE_READ, &fileAttribs, CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH|FILE_ATTRIBUTE_NORMAL, NULL ); // Low priority.. SetPriorityClass( GetCurrentProcess(), IDLE_PRIORITY_CLASS ); bool bSave = !FindArg( "-nosave" ); bool bNoVis = !!FindArg( "-novis" ); bool bNoRad = !!FindArg( "-norad" ); char const *pCFGFile = argv[1]; while( 1 ) { DWORD startTime = GetTickCount(); CConfigFile file; if( file.Read( pCFGFile ) && file.m_Entries.Size() > 0 ) { // Move the first entry in the file to the end. CConfigFile::Entry entry = file.m_Entries[0]; file.m_Entries.Remove( 0 ); file.m_Entries.AddToTail( entry ); if( bSave ) { file.Write( pCFGFile ); } char ssCmd[256]; _snprintf( ssCmd, sizeof(ssCmd), "%s\\win32\\ss.exe", file.m_SSDatabase ); // Grab the SourceSafe tree. AppPrint( "\n\n-------------------------------------------------------------\n" ); AppPrint( "Processing %s\n", entry.m_Filename ); AppPrint( "-------------------------------------------------------------\n" ); AppPrint( "Grabbing resources in %s\n", file.m_SSDatabase ); sprintf( cmd, "ssdir=%s", file.m_SSDatabase ); ret = _putenv( cmd ); // Get the VMF. char vmfFilename[512]; sprintf( vmfFilename, "%s/%s.vmf", entry.m_VMFPath, entry.m_Filename ); sprintf( cmd, "%s get %s -I-", ssCmd, vmfFilename ); ret = RunProcess( cmd ); // Check the timestamp (don't reprocess if it's up-to-date). sprintf( vmfFilename, "%s.vmf", entry.m_Filename ); struct _stat fileStat; ret = _stat( vmfFilename, &fileStat ); long vmfTime = fileStat.st_mtime; if( vmfTime == entry.m_VMFTime ) { AppPrint( "%s is up-to-date\n", vmfFilename ); } else { char localBSPFilename[512]; sprintf( localBSPFilename, "%s.bsp", entry.m_Filename ); // Attrib the bsp if it exists. sprintf( cmd, "attrib -r %s", localBSPFilename ); RunProcess( cmd ); sprintf( cmd, "%s cp %s", ssCmd, file.m_SSResourcePath ); ret = RunProcess( cmd ); if( !FindArg( "-noget" ) ) { sprintf( cmd, "%s get * -R -I-", ssCmd ); ret = RunProcess( cmd ); } // run each tool. char vbspCommand[256], vradCommand[256], vvisCommand[256]; sprintf( vbspCommand, "bin\\vbsp -low %s", entry.m_Filename ); if( entry.m_bFastVis ) sprintf( vvisCommand, "bin\\vvis -fast -low %s", entry.m_Filename ); else sprintf( vvisCommand, "bin\\vvis -low %s", entry.m_Filename ); sprintf( vradCommand, "bin\\vrad -low %s", entry.m_Filename ); if( !RunProcess( vbspCommand ) && (bNoVis || !RunProcess( vvisCommand )) && (bNoRad || !RunProcess( vradCommand )) ) { // Check in the BSP file. char bspFilename[512]; sprintf( bspFilename, "%s/%s.bsp", file.m_SSBSPPath, entry.m_Filename ); // First, try to add it to SS because it may not exist yet. sprintf( cmd, "%s cp %s", ssCmd, file.m_SSBSPPath ); RunProcess(cmd); sprintf( cmd, "%s add %s.bsp -I-", ssCmd, entry.m_Filename ); ret = RunProcess(cmd); // Store off the BSP file temporarily.. char tempFilename[512]; sprintf( localBSPFilename, "%s.bsp", entry.m_Filename ); sprintf( tempFilename, "%s.TEMP", entry.m_Filename ); sprintf( cmd, "del /f %s", tempFilename ); system( cmd ); sprintf( cmd, "attrib -r %s", localBSPFilename ); system( cmd ); ret = MoveFile( localBSPFilename, tempFilename ); if( ret ) { char undoCmd[512]; sprintf( undoCmd, "%s undocheckout %s -I-", ssCmd, bspFilename ); sprintf( cmd, "%s checkout %s -I-", ssCmd, bspFilename ); ret = RunProcess( cmd ); if( !ret ) { // Copy the new BSP file over. DeleteFile( localBSPFilename ); ret = MoveFile( tempFilename, localBSPFilename ); if( ret ) { sprintf( cmd, "%s checkin %s -I-", ssCmd, bspFilename ); ret = RunProcess( cmd ); if( !ret ) { while( !file.Read( pCFGFile ) ) { Sleep( 300 ); } if( bSave ) { CConfigFile::Entry *pEntry = file.FindEntryByFilename( entry.m_Filename ); if( pEntry ) { pEntry->m_VMFTime = vmfTime; while( !file.Write( pCFGFile ) ) { Sleep( 300 ); } } } // Update the timestamp in the config file. AppPrint( "Completed '%s' successfully!\n", entry.m_Filename ); // Send emails. char computerName[256] = {0}; DWORD len = sizeof(computerName); GetComputerName( computerName, &len ); DWORD elapsed = GetTickCount() - startTime; char timeStr[256]; BuildTimeDurationString( elapsed, timeStr ); char subject[1024]; _snprintf( subject, sizeof(subject), "[vmapbuilder] completed '%s' on '%s' in %s", entry.m_Filename, computerName, timeStr ); for( int e=0; e < entry.m_nEMailAddresses; e++ ) { char *pAddr = entry.m_EMailAddresses[e].m_EMailAddress; if( !SendMail( pAddr, subject, subject ) ) { AppPrint( "Unable to send confirmation email to %s\n", pAddr ); } } } else { AppPrint( "ERROR: Can't checkin %s\n", bspFilename ); RunProcess( undoCmd ); } } else { AppPrint( "ERROR: Can't copy back the BSP file %s\n", localBSPFilename ); RunProcess( undoCmd ); } } else { AppPrint( "ERROR: Can't checkout %s\n", bspFilename ); } } else { AppPrint( "ERROR: Can't create temporary file %s\n", tempFilename ); } } else { AppPrint( "Command '%s' failed\n", cmd ); } } } else { AppPrint( "Can't read maplist file: %s\n", pCFGFile ); } // Sleep for a bit in case all maps are processed so we don't kill the network. Sleep( 2000 ); } CloseHandle( g_hOutputFile ); return 0; }
int HandleTCPClient(int clntSocket) { char rxcmdbuf[RCVBUFSIZE]; int recvMsgSize; wchar_t tmp[TMPBUF]; DWORD ret; memset(tmp, 0, 256); memset(rxcmdbuf, 0, RCVBUFSIZE); if ((ret = send(clntSocket, "HI", 2, 0)) != 2) { wsprintf(tmp, L"HandleTCPClient: send HI (0x%x) failed", WSAGetLastError()); WriteLog(tmp); shutdown(clntSocket, 2); closesocket(clntSocket); return -1; } if ((recvMsgSize = recv(clntSocket, rxcmdbuf, RCVBUFSIZE, 0)) < 0) { wsprintf(tmp, L"HandleTCPClient: recv failed(%d)\n", recvMsgSize); WriteLog(tmp); return -1; } DWORD dwPID; WCHAR dest[RCVBUFSIZE]; DWORD dwExitCode = 0; extern TCHAR gServicePath[]; char *usermode_helper = "drbdadm.exe"; wsprintf(dest, L"\"%ws\\%S\" %S", gServicePath, usermode_helper, rxcmdbuf); WriteLog(dest); ret = RunProcess(EXEC_MODE_WIN, SW_NORMAL, dest, NULL, gServicePath, dwPID, INFINITE, &dwExitCode, NULL); // wait!!! wsprintf(tmp, L"RunProcess(%ws) done\n", dest); WriteLog(tmp); if (ret != ERROR_SUCCESS) { wsprintf(tmp, L"Failed to run [%ws] process. GetLastError(%d)", gServicePath, ret); WriteLog(tmp); } // send response rxcmdbuf[0] = (char)dwExitCode; if ((ret = send(clntSocket, rxcmdbuf, 1, 0)) != 1) { wsprintf(tmp, L"HandleTCPClient: send(0x%x) failed !!!!", WSAGetLastError()); WriteLog(tmp); shutdown(clntSocket, 2); closesocket(clntSocket); return -1; } wsprintf(tmp, L"wait for engine BYE message.\n"); // TEST WriteLog(tmp);// TEST if ((recvMsgSize = recv(clntSocket, rxcmdbuf, 3, 0)) != 3) { wsprintf(tmp, L"HandleTCPClient: recv failed(%d) 0x%x\n", recvMsgSize, WSAGetLastError()); WriteLog(tmp); } else { } closesocket(clntSocket); return 0; }
int _tmain(int argc, _TCHAR* argv[]) { TCHAR szPath[MAX_PATH] = { 0, }; DWORD dwSize = GetModuleFileName(NULL, szPath, MAX_PATH); TCHAR * pdest = _tcsrchr(szPath, '\\'); _tcsncpy_s(gServicePath, sizeof(gServicePath) / sizeof(TCHAR), szPath, (size_t)(pdest - szPath)); if (argc < 2) { ExecuteSubProcess(); return 0; } if (_tcsicmp(L"/i", argv[1]) == 0) return Install(szPath, ServiceName); else if (_tcsicmp(L"/k", argv[1]) == 0) return KillService(ServiceName); else if (_tcsicmp(L"/u", argv[1]) == 0) return UnInstall(ServiceName); else if (_tcsicmp(L"/s", argv[1]) == 0) return RunService(ServiceName); else if (_tcsicmp(L"/t", argv[1]) == 0) { DWORD dwPID; WCHAR *szServicePath; WCHAR *cmd = L"drbdadm.exe initial-split-brain minor-6"; WCHAR fullName[MAX_PATH] = {0}; size_t len; errno_t err = _wdupenv_s(&szServicePath, &len, L"DRBD_PATH"); if (err) { // default szServicePath = L"C:\\Program Files\\drbd\\bin"; } if ((wcslen(szServicePath) + wcslen(cmd) + 4) > MAX_PATH) { printf("szServicePath: too big!!\n"); } wcsncpy_s(fullName, szServicePath, wcslen(szServicePath)); wcscat_s(fullName, L"\\"); wcsncat_s(fullName, cmd, wcslen(cmd)); //wnsprintf printf("fullName: %ws\n", fullName); // test! DWORD ret = RunProcess(EXEC_MODE_WIN, SW_NORMAL, NULL, cmd, szServicePath, dwPID, 0, NULL, NULL); free(szServicePath); return ERROR_SUCCESS; } #if 1 // _WIN32_HANDLER_TIMEOUT: test by a separate application, not daemon. remove later else if (_tcsicmp(L"/n", argv[1]) == 0) { // internal test only: no-daemon test unsigned short servPort = DRBD_DAEMON_TCP_PORT; DWORD threadID; if (CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) SockListener, &servPort, 0, (LPDWORD) &threadID) == NULL) { WriteLog(L"pthread_create() failed\n"); return 0; } int i = 0; while (1) { printf("test main loop(%d)...\n", i++); Sleep(10000); } } #endif else { TCHAR msg[256]; _stprintf_s(msg, _T("Usage: drbdService.exe [/i|/k|/u|/s]\n")); WriteLog(msg); return ERROR_INVALID_PARAMETER; } return ERROR_SUCCESS; }