static print_err(char *msg, char *title) { u16 w_msg[1024], w_title[1024]; CE_CharToWide(msg, w_msg); CE_CharToWide(title, w_title); ::MessageBox(NULL, w_msg, w_title, MB_OK); }
BOOL COptHTTP::OnInitDialog() { CDialog::OnInitDialog(); COsmo4 *gpac = GetApp(); TCHAR wTmp[500]; const char *sOpt; sOpt = gf_cfg_get_key(gpac->m_user.config, "Downloader", "CleanCache"); m_CleanCache.SetCheck((sOpt && !stricmp(sOpt, "yes")) ? 1 : 0); sOpt = gf_cfg_get_key(gpac->m_user.config, "Downloader", "RestartFiles"); m_RestartFile.SetCheck((sOpt && !stricmp(sOpt, "yes")) ? 1 : 0); sOpt = gf_cfg_get_key(gpac->m_user.config, "SAXLoader", "Progressive"); m_Progressive.SetCheck((sOpt && !stricmp(sOpt, "yes")) ? 1 : 0); sOpt = gf_cfg_get_key(gpac->m_user.config, "SAXLoader", "MaxDuration"); if (sOpt) { CE_CharToWide((char *) sOpt, (u16 *)wTmp); m_SaxDuration.SetWindowText(wTmp); } else { m_SaxDuration.SetWindowText( _T("30") ); } sOpt = gf_cfg_get_key(gpac->m_user.config, "General", "CacheDirectory"); CE_CharToWide((char *) sOpt, (u16 *)wTmp); if (sOpt) m_CacheDir.SetWindowText(wTmp); OnProgressive(); return TRUE; }
BOOL COptAudio::OnInitDialog() { CDialog::OnInitDialog(); m_AudioSpin.SetBuddy(& m_AudioEdit); m_SpinDur.SetBuddy(& m_AudioDur); m_SpinDur.SetRange(0, 1000); COsmo4 *gpac = GetApp(); const char *sOpt; TCHAR wTmp[500]; sOpt = gf_cfg_get_key(gpac->m_user.config, "Audio", "ForceConfig"); m_ForceConfig.SetCheck( (sOpt && !stricmp(sOpt, "yes")) ? 1 : 0); sOpt = gf_cfg_get_key(gpac->m_user.config, "Audio", "NumBuffers"); if (sOpt) { CE_CharToWide((char *)sOpt, (u16 *)wTmp); m_AudioEdit.SetWindowText(wTmp); } else { m_AudioEdit.SetWindowText(_T("2")); } sOpt = gf_cfg_get_key(gpac->m_user.config, "Audio", "TotalDuration"); if (sOpt) { CE_CharToWide((char *)sOpt, (u16 *)wTmp); m_AudioDur.SetWindowText(wTmp); } else { m_AudioDur.SetWindowText(_T("200")); } OnForceAudio(); sOpt = gf_cfg_get_key(gpac->m_user.config, "Audio", "NoResync"); if (sOpt && !stricmp(sOpt, "yes")) { m_AudioResync.SetCheck(1); } else { m_AudioResync.SetCheck(0); } /*driver enum*/ while (m_DriverList.GetCount()) m_DriverList.DeleteString(0); sOpt = gf_cfg_get_key(gpac->m_user.config, "Audio", "DriverName"); u32 count = gf_modules_get_count(gpac->m_user.modules); GF_BaseInterface *ifce; s32 select = 0; s32 to_sel = 0; for (u32 i=0; i<count; i++) { ifce = gf_modules_load_interface(gpac->m_user.modules, i, GF_AUDIO_OUTPUT_INTERFACE); if (!ifce) continue; if (sOpt && !stricmp(((GF_BaseInterface *)ifce)->module_name, sOpt)) select = to_sel; CE_CharToWide((char *) ((GF_BaseInterface *)ifce)->module_name, (u16 *)wTmp); m_DriverList.AddString(wTmp); gf_modules_close_interface(ifce); to_sel++; } m_DriverList.SetCurSel(select); return TRUE; }
GF_EXPORT GF_Err gf_move_file(const char *fileName, const char *newFileName) { #if defined(_WIN32_WCE) TCHAR swzName[MAX_PATH]; TCHAR swzNewName[MAX_PATH]; CE_CharToWide((char*)fileName, swzName); CE_CharToWide((char*)newFileName, swzNewName); return (MoveFile(swzName, swzNewName) == 0 ) ? GF_IO_ERR : GF_OK; #elif defined(WIN32) /* success if != 0 */ return (MoveFile(fileName, newFileName) == 0 ) ? GF_IO_ERR : GF_OK; #else GF_Err e = GF_IO_ERR; char cmd[1024], *arg1, *arg2; if (!fileName || !newFileName) return GF_IO_ERR; arg1 = gf_sanetize_single_quoted_string(fileName); arg2 = gf_sanetize_single_quoted_string(newFileName); if (snprintf(cmd, sizeof cmd, "mv %s %s", arg1, arg2) >= sizeof cmd) goto error; e = (system(cmd) == 0) ? GF_OK : GF_IO_ERR; error: gf_free(arg1); gf_free(arg2); return e; #endif }
GF_EXPORT GF_Err gf_move_file(const char *fileName, const char *newFileName) { #if defined(_WIN32_WCE) TCHAR swzName[MAX_PATH]; TCHAR swzNewName[MAX_PATH]; CE_CharToWide((char*)fileName, swzName); CE_CharToWide((char*)newFileName, swzNewName); return (MoveFile(swzName, swzNewName) == 0 ) ? GF_IO_ERR : GF_OK; #elif defined(WIN32) /* success if != 0 */ BOOL op_result; wchar_t* wcsFileName = utf8_to_wcs(fileName); wchar_t* wcsNewFileName = utf8_to_wcs(newFileName); if (!wcsFileName || !wcsNewFileName) { if (wcsFileName) gf_free(wcsFileName); if (wcsNewFileName) gf_free(wcsNewFileName); return GF_IO_ERR; } op_result = MoveFileW(wcsFileName, wcsNewFileName); gf_free(wcsFileName); gf_free(wcsNewFileName); return ( op_result == 0 ) ? GF_IO_ERR : GF_OK; #else GF_Err e = GF_IO_ERR; char cmd[1024], *arg1, *arg2; if (!fileName || !newFileName) return GF_IO_ERR; arg1 = gf_sanetize_single_quoted_string(fileName); arg2 = gf_sanetize_single_quoted_string(newFileName); if (snprintf(cmd, sizeof cmd, "mv %s %s", arg1, arg2) >= sizeof cmd) goto error; #if defined(GPAC_IPHONE) && (__IPHONE_OS_VERSION_MAX_ALLOWED >= 80000) { pid_t pid; char *argv[3]; argv[0] = "mv"; argv[1] = cmd; argv[2] = NULL; posix_spawn(&pid, argv[0], NULL, NULL, argv, environ); waitpid(pid, NULL, 0); } #else e = (system(cmd) == 0) ? GF_OK : GF_IO_ERR; #endif error: gf_free(arg1); gf_free(arg2); return e; #endif }
BOOL COptDecoder::OnInitDialog() { u32 i; CDialog::OnInitDialog(); COsmo4 *gpac = GetApp(); const char *sOpt; /*audio dec enum*/ while (m_Audio.GetCount()) m_Audio.DeleteString(0); sOpt = gf_cfg_get_key(gpac->m_user.config, "Systems", "DefAudioDec"); u32 count = gf_modules_get_count(gpac->m_user.modules); GF_BaseDecoder *ifce; s32 select = 0; s32 to_sel = 0; for (i=0; i<count; i++) { ifce = (GF_BaseDecoder *) gf_modules_load_interface(gpac->m_user.modules, i, GF_MEDIA_DECODER_INTERFACE); if (!ifce) continue; if (ifce->CanHandleStream(ifce, GF_STREAM_AUDIO, NULL, 0)) { if (sOpt && !stricmp(((GF_BaseInterface *)ifce)->module_name, sOpt)) select = to_sel; TCHAR wzTmp[500]; CE_CharToWide((char *) ifce->module_name, (u16 *)wzTmp); m_Audio.AddString(wzTmp); to_sel++; } gf_modules_close_interface((GF_BaseInterface *) ifce); } m_Audio.SetCurSel(select); /*audio dec enum*/ while (m_Video.GetCount()) m_Video.DeleteString(0); sOpt = gf_cfg_get_key(gpac->m_user.config, "Systems", "DefVideoDec"); count = gf_modules_get_count(gpac->m_user.modules); select = 0; to_sel = 0; for (i=0; i<count; i++) { ifce = (GF_BaseDecoder *) gf_modules_load_interface(gpac->m_user.modules, i, GF_MEDIA_DECODER_INTERFACE); if (!ifce) continue; if (ifce->CanHandleStream(ifce, GF_STREAM_VISUAL, NULL, 0)) { if (sOpt && !stricmp(((GF_BaseInterface *)ifce)->module_name, sOpt)) select = to_sel; TCHAR wzTmp[500]; CE_CharToWide((char *) ifce->module_name, (u16 *)wzTmp); m_Video.AddString(wzTmp); to_sel++; } gf_modules_close_interface((GF_BaseInterface *) ifce); } m_Video.SetCurSel(select); return TRUE; }
GF_EXPORT u64 gf_file_modification_time(const char *filename) { #if defined(_WIN32_WCE) WCHAR _file[GF_MAX_PATH]; WIN32_FIND_DATA FindData; HANDLE fh; ULARGE_INTEGER uli; ULONGLONG time_ms; BOOL ret; CE_CharToWide((char *) filename, _file); fh = FindFirstFile(_file, &FindData); if (fh == INVALID_HANDLE_VALUE) return 0; uli.LowPart = FindData.ftLastWriteTime.dwLowDateTime; uli.HighPart = FindData.ftLastWriteTime.dwHighDateTime; ret = FindClose(fh); if (!ret) { DWORD err = GetLastError(); GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("[core] FindClose() in gf_file_modification_time() returned the following error code: %d\n", err)); } time_ms = uli.QuadPart/10000; return time_ms; #elif defined(WIN32) && !defined(__GNUC__) struct _stat64 sb; if (_stat64(filename, &sb) != 0) return 0; return sb.st_mtime; #else struct stat sb; if (stat(filename, &sb) != 0) return 0; return sb.st_mtime; #endif return 0; }
GF_EXPORT GF_Err gf_mkdir(char* DirPathName) { #if defined (_WIN32_WCE) TCHAR swzName[MAX_PATH]; BOOL res; CE_CharToWide(DirPathName, swzName); res = CreateDirectory(swzName, NULL); if (! res) { int err = GetLastError(); GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("Cannot create directory %s: last error %d\n", DirPathName, err )); } #elif defined (WIN32) int res = mkdir(DirPathName); if (res==-1) { int err = GetLastError(); GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("Cannot create directory %s: last error %d\n", DirPathName, err )); } #else int res = mkdir(DirPathName, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); if (res==-1) { if(errno == 17) { GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("Cannot create directory %s, it already exists: last error %d \n", DirPathName, errno )); return GF_BAD_PARAM; } else { GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("Cannot create directory %s: last error %d\n", DirPathName, errno )); return GF_IO_ERR; } } #endif return GF_OK; }
void refresh_recent_files() { #ifdef _WIN32_WCE u32 count = gf_cfg_get_key_count(user.config, "RecentFiles"); HMENU hMenu = (HMENU)SendMessage(g_hwnd_menu, SHCMBM_GETSUBMENU, 0, ID_MENU_FILE); /*pos is hardcoded*/ hMenu = GetSubMenu(hMenu, 2); while (RemoveMenu(hMenu, 0, MF_BYPOSITION)) {} for (u32 i=0; i<count; i++) { TCHAR txt[100]; char *name; const char *sOpt = gf_cfg_get_key_name(user.config, "RecentFiles", i); name = strrchr(sOpt, '\\'); if (!name) name = strrchr(sOpt, '/'); if (!name) name = (char *) sOpt; else name += 1; CE_CharToWide(name, (u16 *) txt); AppendMenu(hMenu, MF_STRING, IDM_OPEN_FILE1+i, txt); } #endif }
GF_EXPORT GF_Err gf_delete_file(const char *fileName) { if (!fileName) { GF_LOG(GF_LOG_WARNING, GF_LOG_CORE, ("gf_delete_file deletes nothing - ignoring\n")); return GF_OK; } #if defined(_WIN32_WCE) TCHAR swzName[MAX_PATH]; CE_CharToWide((char*)fileName, swzName); return (DeleteFile(swzName)==0) ? GF_IO_ERR : GF_OK; #elif defined(WIN32) /* success if != 0 */ { BOOL op_result; wchar_t* wcsFileName = utf8_to_wcs(fileName); if (!wcsFileName) return GF_IO_ERR; op_result = DeleteFileW(wcsFileName); gf_free(wcsFileName); return (op_result==0) ? GF_IO_ERR : GF_OK; } #else /* success is == 0 */ return ( remove(fileName) == 0) ? GF_OK : GF_IO_ERR; #endif }
GF_EXPORT Bool gf_dir_exists(const char* DirPathName) { #if defined (_WIN32_WCE) TCHAR swzName[MAX_PATH]; BOOL res; DWORD att; CE_CharToWide(DirPathName, swzName); att = GetFileAttributes(swzName); return (att != INVALID_FILE_ATTRIBUTES && (att & FILE_ATTRIBUTE_DIRECTORY)) ? GF_TRUE : GF_FALSE; #elif defined (WIN32) DWORD att; wchar_t* wcsDirPathName = utf8_to_wcs(DirPathName); if (!wcsDirPathName) return GF_FALSE; att = GetFileAttributesW(wcsDirPathName); gf_free(wcsDirPathName); return (att != INVALID_FILE_ATTRIBUTES && (att & FILE_ATTRIBUTE_DIRECTORY)) ? GF_TRUE : GF_FALSE; #else DIR* dir = opendir(DirPathName); if (!dir) return GF_FALSE; closedir(dir); return GF_TRUE; #endif return GF_FALSE; }
GF_Err gf_rmdir(char *DirPathName) { #if defined (_WIN32_WCE) TCHAR swzName[MAX_PATH]; BOOL res; CE_CharToWide(DirPathName, swzName); res = RemoveDirectory(swzName); if (! res) { int err = GetLastError(); GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("Cannot delete director %s: last error %d\n", DirPathName, err )); } #elif defined (WIN32) int res = rmdir(DirPathName); if (res==-1) { int err = GetLastError(); GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("Cannot delete director %s: last error %d\n", DirPathName, err )); return GF_IO_ERR; } #else int res = rmdir(DirPathName); if (res==-1) { GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("Cannot delete director %s: last error %d\n", DirPathName, errno )); return GF_IO_ERR; } #endif return GF_OK; }
void process_list_change(HWND hWnd, Bool add_to_pl) { TCHAR sTxt[GF_MAX_PATH]; if (!SendMessage(hList, LB_GETSELCOUNT, 0, 0)) return; u32 idx = SendMessage(hList, LB_GETCURSEL, 0, 0); SendMessage(hList, LB_GETTEXT, idx, (LPARAM)(LPCTSTR) sTxt); DWORD param = SendMessage(hList, LB_GETITEMDATA, idx, 0); if (param==1) { if (!wcscmp(sTxt, _T("+ ..") ) ) { if (add_to_pl) return; current_dir[strlen((const char *) current_dir)-1] = 0; char *b = strrchr((const char *) current_dir, '\\'); if (b) b[1] = 0; else b[0] = '\\'; CE_CharToWide((char *) current_dir, (u16 *) w_current_dir); set_directory(w_current_dir); } else { if (add_to_pl) { char dir[MAX_PATH]; TCHAR wdir[MAX_PATH]; wcscpy(wdir, w_current_dir); wcscat(wdir, sTxt+2); wcscat(wdir, _T("\\")); CE_WideToChar((u16 *) wdir, (char *) dir); gf_enum_directory(dir, GF_FALSE, add_files, NULL, NULL); } else { wcscat(w_current_dir, sTxt+2); wcscat(w_current_dir, _T("\\")); CE_WideToChar((u16 *) w_current_dir, (char *) current_dir); set_directory(w_current_dir); } } } else { char szTxt[1024]; CE_WideToChar((u16 *) sTxt, (char *) szTxt); strcpy((char *) out_url, (const char *) current_dir); strcat(out_url, szTxt); if (add_to_pl) { gf_cfg_set_key(cfg, "Playlist", out_url, ""); strcpy(out_url, ""); } else { if (playlist_mode) { const char *file; char szPLE[20]; sprintf(szPLE, "%d", idx); gf_cfg_set_key(cfg, "General", "PLEntry", szPLE); file = gf_cfg_get_key_name(cfg, "Playlist", idx); strcpy(out_url, file); } gf_cfg_set_key(cfg, "General", "LastWorkingDir", (const char *) current_dir); EndDialog(hWnd, 1); } } }
BOOL COptRender::OnInitDialog() { CDialog::OnInitDialog(); COsmo4 *gpac = GetApp(); const char *sOpt; sOpt = gf_cfg_get_key(gpac->m_user.config, "Compositor", "DirectDraw"); if (sOpt && !stricmp(sOpt, "yes")) { m_DirectRender.SetCheck(1); } else { m_DirectRender.SetCheck(0); } sOpt = gf_cfg_get_key(gpac->m_user.config, "Compositor", "ScalableZoom"); if (sOpt && !stricmp(sOpt, "no")) { m_Scalable.SetCheck(0); } else { m_Scalable.SetCheck(1); } sOpt = gf_cfg_get_key(gpac->m_user.config, "Compositor", "ForceSceneSize"); if (sOpt && !stricmp(sOpt, "yes")) { m_ForceSize.SetCheck(1); } else { m_ForceSize.SetCheck(0); } sOpt = gf_cfg_get_key(gpac->m_user.config, "Compositor", "FrameRate"); if (!sOpt) sOpt = "30.0"; s32 select = 0; while (m_BIFSRate.GetCount()) m_BIFSRate.DeleteString(0); for (s32 i = 0; i<NUM_RATES; i++) { TCHAR szText[100]; CE_CharToWide(BIFSRates[i], (u16 *)szText); m_BIFSRate.AddString(szText); if (sOpt && !stricmp(sOpt, BIFSRates[i]) ) select = i; } m_BIFSRate.SetCurSel(select); sOpt = gf_cfg_get_key(gpac->m_user.config, "Compositor", "HighSpeed"); m_HighSpeed.SetCheck((sOpt && !stricmp(sOpt, "yes")) ? 1 : 0); sOpt = gf_cfg_get_key(gpac->m_user.config, "Compositor", "AntiAlias"); while (m_Antialias.GetCount()) m_Antialias.DeleteString(0); m_Antialias.AddString(_T("None")); m_Antialias.AddString(_T("Text only")); m_Antialias.AddString(_T("Complete")); select = 2; if (sOpt && !stricmp(sOpt, "Text")) select = 1; else if (sOpt && !stricmp(sOpt, "None")) select = 0; m_Antialias.SetCurSel(select); return TRUE; }
Bool enum_dirs(void *cbk, char *name, char *path) { TCHAR w_name[GF_MAX_PATH], w_str_name[GF_MAX_PATH]; CE_CharToWide(name, (u16 *) w_name); wcscpy(w_str_name, _T("+ ")); wcscat(w_str_name, w_name); int iRes = SendMessage(hList, LB_ADDSTRING, 0, (LPARAM)(LPCTSTR) w_str_name); SendMessage(hList, LB_SETITEMDATA, iRes, (LPARAM) 1); return GF_FALSE; }
Bool enum_files(void *cbk, char *name, char *path) { TCHAR w_name[GF_MAX_PATH]; if (!bViewUnknownTypes && extension_list) { char *ext = strrchr(name, '.'); if (!ext || !strstr(extension_list, ext+1)) return GF_FALSE; } CE_CharToWide(name, (u16 *) w_name); SendMessage(hList, LB_ADDSTRING, 0, (LPARAM)(LPCTSTR) w_name); return GF_FALSE; }
BOOL COptSystems::OnInitDialog() { CDialog::OnInitDialog(); COsmo4 *gpac = GetApp(); const char *sOpt; sOpt = gf_cfg_get_key(gpac->m_user.config, "Systems", "Language3CC"); if (!sOpt) sOpt = "eng"; s32 select = 0; while (m_Lang.GetCount()) m_Lang.DeleteString(0); u32 i=0; while (GF_ISO639_Lang[i]) { TCHAR szTmp[100]; /*only use common languages (having both 2- and 3-char code names)*/ if (GF_ISO639_Lang[i+2][0]) { CE_CharToWide( (char *)GF_ISO639_Lang[i], (u16 *)szTmp); m_Lang.AddString(szTmp); if (sOpt && !stricmp(sOpt, GF_ISO639_Lang[i+1])) select = m_Lang.GetCount() - 1; } i+=3; } m_Lang.SetCurSel(select); /*system config*/ sOpt = gf_cfg_get_key(gpac->m_user.config, "Systems", "ThreadingPolicy"); select = 0; while (m_Threading.GetCount()) m_Threading.DeleteString(0); m_Threading.AddString(_T("Single Thread")); m_Threading.AddString(_T("Mutli Thread")); if (sOpt && !stricmp(sOpt, "Multi")) select = 1; m_Threading.AddString(_T("Free")); if (sOpt && !stricmp(sOpt, "Free")) select = 2; m_Threading.SetCurSel(select); sOpt = gf_cfg_get_key(gpac->m_user.config, "Systems", "ForceSingleClock"); if (sOpt && !stricmp(sOpt, "yes")) { m_ForceDuration.SetCheck(1); } else { m_ForceDuration.SetCheck(0); } sOpt = gf_cfg_get_key(gpac->m_user.config, "Systems", "AlwaysDrawBIFS"); if (sOpt && !stricmp(sOpt, "yes")) { m_BifsAlwaysDrawn.SetCheck(1); } else { m_BifsAlwaysDrawn.SetCheck(0); } return TRUE; }
BOOL InitFileDialog(const HWND hWnd) { TCHAR psz[80]; ZeroMemory(psz, sizeof(psz)); SHINITDLGINFO sid; ZeroMemory(&sid, sizeof(sid)); sid.dwMask = SHIDIM_FLAGS; sid.dwFlags = SHIDIF_SIZEDLGFULLSCREEN; sid.hDlg = hWnd; if (FALSE == SHInitDialog(&sid)) return FALSE; SHMENUBARINFO mbi; ZeroMemory(&mbi, sizeof(SHMENUBARINFO)); mbi.cbSize = sizeof(SHMENUBARINFO); mbi.hwndParent = hWnd; mbi.nToolBarId = IDR_MENU_OPEN; mbi.hInstRes = g_hInst; if (FALSE == SHCreateMenuBar(&mbi)) { return FALSE; } g_hWndMenuBar = mbi.hwndMB; ShowWindow(g_hWndMenuBar, SW_SHOW); the_wnd = hWnd; hDirTxt = GetDlgItem(hWnd, IDC_DIRNAME); hList = GetDlgItem(hWnd, IDC_FILELIST); g_hMenuView = (HMENU)SendMessage(g_hWndMenuBar, SHCMBM_GETSUBMENU, 0, ID_OF_VIEW); RECT rc; GetClientRect(hWnd, &rc); u32 caption_h = GetSystemMetrics(SM_CYCAPTION) - 3; MoveWindow(hDirTxt, 0, 0, rc.right - rc.left, caption_h, 1); MoveWindow(hList, 0, caption_h, rc.right - rc.left, rc.bottom - rc.top - caption_h, 1); if (playlist_mode) { refresh_playlist(); } else { if (!strcmp((const char *) current_dir, "\\")) { char *opt = (char *) gf_cfg_get_key(cfg, "General", "LastWorkingDir"); if (opt) CE_CharToWide(opt, (u16 *) w_current_dir); } set_directory(w_current_dir); } switch_menu_pl(); return TRUE; }
void set_status(char *state) { if (show_status && g_hwnd_status) { #ifdef _WIN32_WCE TCHAR wstate[1024]; CE_CharToWide(state, (u16 *) wstate); SendMessage(g_hwnd_status, WM_SETTEXT, 0, (LPARAM) wstate); #else SendMessage(g_hwnd_status, WM_SETTEXT, 0, (LPARAM) state); #endif last_state_time = GetTickCount(); } }
BOOL COptFont::OnInitDialog() { u32 i; GF_BaseInterface *ifce; CDialog::OnInitDialog(); COsmo4 *gpac = GetApp(); TCHAR wTmp[500]; const char *sOpt; /*video drivers enum*/ while (m_Fonts.GetCount()) m_Fonts.DeleteString(0); sOpt = gf_cfg_get_key(gpac->m_user.config, "FontEngine", "DriverName"); s32 to_sel = 0; s32 select = 0; u32 count = gf_modules_get_count(gpac->m_user.modules); for (i=0; i<count; i++) { ifce = gf_modules_load_interface(gpac->m_user.modules, i, GF_FONT_READER_INTERFACE); if (!ifce) continue; if (sOpt && !stricmp(((GF_BaseInterface *)ifce)->module_name, sOpt)) select = to_sel; CE_CharToWide((char *) ifce->module_name, (u16 *)wTmp); m_Fonts.AddString(wTmp); gf_modules_close_interface(ifce); to_sel++; } m_Fonts.SetCurSel(select); sOpt = gf_cfg_get_key(gpac->m_user.config, "FontEngine", "FontDirectory"); CE_CharToWide((char *)sOpt, (u16 *)wTmp); if (sOpt) m_BrowseFont.SetWindowText(wTmp); sOpt = gf_cfg_get_key(gpac->m_user.config, "Compositor", "TextureTextMode"); m_UseTexture.SetCheck( (!sOpt || stricmp(sOpt, "Never")) ? 1 : 0); return TRUE; }
BOOL CALLBACK AboutDialogProc(const HWND hWnd, const UINT Msg, const WPARAM wParam, const LPARAM lParam) { BOOL ret = TRUE; switch (Msg) { case WM_INITDIALOG: { char szText[4096]; HWND hctl = GetDlgItem(hWnd, IDC_NAMECTRL); sprintf(szText, "GPAC/Osmo4\nversion %s", GPAC_FULL_VERSION); #ifdef _WIN32_WCE TCHAR psz[80]; ZeroMemory(psz, sizeof(psz)); SHINITDLGINFO sid; ZeroMemory(&sid, sizeof(sid)); sid.dwMask = SHIDIM_FLAGS; sid.dwFlags = SHIDIF_SIZEDLGFULLSCREEN; sid.hDlg = hWnd; SHInitDialog(&sid); SHMENUBARINFO mbi; memset(&mbi, 0, sizeof(SHMENUBARINFO)); mbi.cbSize = sizeof(SHMENUBARINFO); mbi.hwndParent = hWnd; mbi.nToolBarId = IDR_ABOUT_MENU; mbi.hInstRes = g_hinst; mbi.nBmpId = 0; mbi.cBmpImages = 0; SHCreateMenuBar(&mbi); u16 swText[4096]; CE_CharToWide(szText, swText); SetWindowText(hctl, (LPCWSTR) swText); #else SetWindowText(hctl, szText); #endif MoveWindow(hctl, 0, 0, screen_w, 40, 1); MoveWindow(hWnd, 0, 0, screen_w, disp_w, 1); } break; case WM_COMMAND: case WM_CLOSE: EndDialog(hWnd, 0); break; default: ret = FALSE; } return ret; }
GF_EXPORT GF_Err gf_delete_file(const char *fileName) { #if defined(_WIN32_WCE) TCHAR swzName[MAX_PATH]; CE_CharToWide((char*)fileName, swzName); return (DeleteFile(swzName)==0) ? GF_IO_ERR : GF_OK; #elif defined(WIN32) /* success if != 0 */ return (DeleteFile(fileName)==0) ? GF_IO_ERR : GF_OK; #else /* success is == 0 */ return ( remove(fileName) == 0) ? GF_OK : GF_IO_ERR; #endif }
/*enumerate directories*/ M4Err DIR_Enum(const char *dir, Bool enum_directory, Bool (*enum_dir_item)(void *cbck, char *item_name, char *item_path), void *cbck) { unsigned char _path[M4_MAX_PATH]; unsigned short path[M4_MAX_PATH]; unsigned char file[M4_MAX_PATH], filepath[M4_MAX_PATH]; WIN32_FIND_DATA FindData; HANDLE SearchH; if (!dir) return M4BadParam; if (dir[strlen(dir) - 1] != M4_PATH_SEPARATOR) { sprintf(_path, "%s*", dir); } else { sprintf(_path, "%s%c*", dir); } CE_CharToWide(_path, path); SearchH= FindFirstFile(path, &FindData); if (SearchH == INVALID_HANDLE_VALUE) return M4IOErr; _path[strlen(_path)-1] = 0; while (SearchH != INVALID_HANDLE_VALUE) { if (!wcscmp(FindData.cFileName, _T(".") )) goto next; if (!wcscmp(FindData.cFileName, _T("..") )) goto next; if (!enum_directory && (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) goto next; if (enum_directory && !(FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) goto next; CE_WideToChar(FindData.cFileName, file); strcpy(filepath, _path); strcat(filepath, file); if (enum_dir_item(cbck, file, filepath)) { FindClose(SearchH); break; } next: if (!FindNextFile(SearchH, &FindData)) { FindClose(SearchH); break; } } return M4OK; }
GF_EXPORT GF_Err gf_delete_file(const char *fileName) { if (!fileName) { GF_LOG(GF_LOG_WARNING, GF_LOG_CORE, ("gf_delete_file deletes nothing - ignoring\n")); return GF_OK; } #if defined(_WIN32_WCE) TCHAR swzName[MAX_PATH]; CE_CharToWide((char*)fileName, swzName); return (DeleteFile(swzName)==0) ? GF_IO_ERR : GF_OK; #elif defined(WIN32) /* success if != 0 */ return (DeleteFile(fileName)==0) ? GF_IO_ERR : GF_OK; #else /* success is == 0 */ return ( remove(fileName) == 0) ? GF_OK : GF_IO_ERR; #endif }
void do_copy_paste() { if (!OpenClipboard(g_hwnd)) return; /*or we are editing text and clipboard is not empty*/ if (IsClipboardFormatAvailable(CF_TEXT) && (gf_term_paste_text(term, NULL, 1)==GF_OK)) { HGLOBAL hglbCopy = GetClipboardData(CF_TEXT); if (hglbCopy) { #ifdef _WIN32_WCE char szString[1024]; LPCTSTR paste_string = (LPCTSTR) GlobalLock(hglbCopy); CE_WideToChar((u16 *) paste_string, szString); gf_term_paste_text(term, szString, 0); #else char *szString = (char *)GlobalLock(hglbCopy); gf_term_paste_text(term, szString, 0); #endif GlobalUnlock(hglbCopy); } } /*we have something to copy*/ else if (gf_term_get_text_selection(term, 1)!=NULL) { u32 len; const char *text = gf_term_get_text_selection(term, 0); if (text && strlen(text)) { EmptyClipboard(); len = strlen(text); #ifdef _WIN32_WCE HGLOBAL hglbCopy = GlobalAlloc(GMEM_MOVEABLE, (len + 1) * sizeof(u16)); LPCTSTR new_string = (LPCTSTR) GlobalLock(hglbCopy); CE_CharToWide((char*)text, (u16*)new_string); #else HGLOBAL hglbCopy = GlobalAlloc(GMEM_MOVEABLE, (len + 1) * sizeof(u8)); char *new_string = (char*) GlobalLock(hglbCopy); strcpy(new_string, text); #endif GlobalUnlock(hglbCopy); SetClipboardData(CF_TEXT, hglbCopy); } } CloseClipboard(); }
BOOL OpenDlg::OnInitDialog() { TCHAR w_str[5000]; CDialog::OnInitDialog(); COsmo4 *app = GetApp(); const char *sOpt; u32 i=0; while (m_URLs.GetCount()) m_URLs.DeleteString(0); while (1) { sOpt = gf_cfg_get_key_name(app->m_user.config, "RecentFiles", i); if (!sOpt) break; CE_CharToWide((char *) sOpt, (u16 *)w_str); m_URLs.AddString(w_str); i++; } SetFocus(); return TRUE; }
LONG CMainFrame::OnNavigate(WPARAM /*wParam*/, LPARAM /*lParam*/) { COsmo4 *app = GetApp(); char to_url[MAX_PATH]; CE_WideToChar((LPTSTR) (LPCTSTR) app->m_navigate_url, to_url); if (gf_term_is_supported_url(app->m_term, to_url, 1, app->m_no_mime_fetch)) { char fileName[MAX_PATH]; TCHAR w_to_url[MAX_PATH]; CE_WideToChar((LPTSTR) (LPCTSTR) app->m_filename, fileName); char *str = gf_url_concatenate(fileName, to_url); if (!str) str = strdup(to_url); CE_CharToWide(str, w_to_url); free(str); app->m_filename = w_to_url; Open(0, 0); } else { SHELLEXECUTEINFO info; console_message = app->m_navigate_url; console_err = GF_OK; PostMessage(WM_CONSOLEMSG); if (m_full_screen) { OnViewFullscreen(); app->ShowTaskBar(1); m_restore_fs = 1; } memset(&info, 0, sizeof(SHELLEXECUTEINFO)); info.cbSize = sizeof(SHELLEXECUTEINFO); info.lpVerb = L"open"; info.fMask = SEE_MASK_NOCLOSEPROCESS; info.lpFile = L"iexplore"; info.lpParameters = (LPCTSTR) app->m_navigate_url; info.nShow = SW_SHOWNORMAL; ShellExecuteEx(&info); } return 1; }
void refresh_playlist() { TCHAR w_name[GF_MAX_PATH]; u32 count, i; SetWindowText(hDirTxt, _T("Playlist")); SendMessage(hList, LB_RESETCONTENT, 0, 0); count = gf_cfg_get_key_count(cfg, "Playlist"); for (i=0; i<count; i++) { const char *file = gf_cfg_get_key_name(cfg, "Playlist", i); char *name = strrchr(file, '\\'); if (!name) name = strrchr(file, '/'); CE_CharToWide(name ? name+1 : (char *) file, (u16 *) w_name); SendMessage(hList, LB_ADDSTRING, 0, (LPARAM)(LPCTSTR) w_name); } i = 0; const char *ple = gf_cfg_get_key(cfg, "General", "PLEntry"); i = ple ? atoi(ple) : 0; if (i>=count) i=0; SendMessage(hList, LB_SETCURSEL, i, 0); SetFocus(hList); }
Bool GPAC_EventProc(void *ptr, GF_Event *evt) { switch (evt->type) { case GF_EVENT_DURATION: Duration = (u32) (evt->duration.duration*1000); CanSeek = evt->duration.can_seek; break; case GF_EVENT_MESSAGE: { if (!evt->message.message) return 0; GF_LOG(GF_LOG_ERROR, GF_LOG_CONSOLE, ("%s: %s\n", evt->message.message, gf_error_to_string(evt->message.error))); //set_status((char *) evt->message.message); } break; case GF_EVENT_PROGRESS: { char *szTitle = ""; if (evt->progress.progress_type==0) szTitle = "Buffer "; else if (evt->progress.progress_type==1) szTitle = "Download "; else if (evt->progress.progress_type==2) szTitle = "Import "; cbk_on_progress(szTitle, evt->progress.done, evt->progress.total); } break; case GF_EVENT_SIZE: break; case GF_EVENT_RESOLUTION: recompute_res(evt->size.width, evt->size.height); do_layout(1); break; case GF_EVENT_SCENE_SIZE: do_layout(1); break; case GF_EVENT_DBLCLICK: set_full_screen(); return 0; case GF_EVENT_CONNECT: if (evt->connect.is_connected) { is_connected = 1; if (!backlight_off) set_backlight_state(1); refresh_recent_files(); navigation_on = (gf_term_get_option(term, GF_OPT_NAVIGATION)==GF_NAVIGATE_NONE) ? 0 : 1; } else { navigation_on = 0; is_connected = 0; Duration = 0; } break; case GF_EVENT_EOS: if (Duration>2000) gf_term_play_from_time(term, 0, 0); break; case GF_EVENT_QUIT: PostMessage(g_hwnd, WM_DESTROY, 0, 0); break; case GF_EVENT_KEYDOWN: switch (evt->key.key_code) { case GF_KEY_ENTER: if (full_screen) set_full_screen(); break; case GF_KEY_1: ctrl_mod_down = !ctrl_mod_down; evt->key.key_code = GF_KEY_CONTROL; evt->type = ctrl_mod_down ? GF_EVENT_KEYDOWN : GF_EVENT_KEYUP; gf_term_user_event(term, evt); break; case GF_KEY_MEDIAPREVIOUSTRACK: playlist_act = 2; break; case GF_KEY_MEDIANEXTTRACK: playlist_act = 1; break; } break; case GF_EVENT_NAVIGATE: if (gf_term_is_supported_url(term, evt->navigate.to_url, 1, 1)) { gf_term_navigate_to(term, evt->navigate.to_url); return 1; } else { #ifdef _WIN32_WCE u16 dst[1024]; #endif SHELLEXECUTEINFO info; /* if (full_screen) gf_term_set_option(term, GF_OPT_FULLSCREEN, 0); full_screen = 0; */ memset(&info, 0, sizeof(SHELLEXECUTEINFO)); info.cbSize = sizeof(SHELLEXECUTEINFO); info.lpVerb = _T("open"); info.fMask = SEE_MASK_NOCLOSEPROCESS; info.lpFile = _T("iexplore"); #ifdef _WIN32_WCE CE_CharToWide((char *) evt->navigate.to_url, dst); info.lpParameters = (LPCTSTR) dst; #else info.lpParameters = evt->navigate.to_url; #endif info.nShow = SW_SHOWNORMAL; ShellExecuteEx(&info); } return 1; } return 0; }
/*enumerate directories*/ GF_EXPORT GF_Err gf_enum_directory(const char *dir, Bool enum_directory, gf_enum_dir_item enum_dir_fct, void *cbck, const char *filter) { char item_path[GF_MAX_PATH]; GF_FileEnumInfo file_info; #if defined(_WIN32_WCE) char _path[GF_MAX_PATH]; unsigned short path[GF_MAX_PATH]; unsigned short w_filter[GF_MAX_PATH]; char file[GF_MAX_PATH]; #else char path[GF_MAX_PATH], *file; #endif #ifdef WIN32 WIN32_FIND_DATA FindData; HANDLE SearchH; #else DIR *the_dir; struct dirent* the_file; struct stat st; #endif if (!dir || !enum_dir_fct) return GF_BAD_PARAM; if (filter && (!strcmp(filter, "*") || !filter[0])) filter=NULL; memset(&file_info, 0, sizeof(GF_FileEnumInfo) ); if (!strcmp(dir, "/")) { #if defined(WIN32) && !defined(_WIN32_WCE) u32 len; char *drives, *volume; len = GetLogicalDriveStrings(0, NULL); drives = gf_malloc(sizeof(char)*(len+1)); drives[0]=0; GetLogicalDriveStrings(len, drives); len = (u32) strlen(drives); volume = drives; file_info.directory = GF_TRUE; file_info.drive = GF_TRUE; while (len) { enum_dir_fct(cbck, volume, "", &file_info); volume += len+1; len = (u32) strlen(volume); } gf_free(drives); return GF_OK; #elif defined(__SYMBIAN32__) RFs iFs; TDriveList aList; iFs.Connect(); iFs.DriveList(aList); for (TInt i=0; i<KMaxDrives; i++) { if (aList[i]) { char szDrive[10]; TChar aDrive; iFs.DriveToChar(i, aDrive); sprintf(szDrive, "%c:", (TUint)aDrive); enum_dir_fct(cbck, szDrive, "", &file_info); } } iFs.Close(); FlushItemList(); return GF_OK; #endif } #if defined (_WIN32_WCE) switch (dir[strlen(dir) - 1]) { case '/': case '\\': sprintf(_path, "%s*", dir); break; default: sprintf(_path, "%s%c*", dir, GF_PATH_SEPARATOR); break; } CE_CharToWide(_path, path); CE_CharToWide((char *)filter, w_filter); #elif defined(WIN32) switch (dir[strlen(dir) - 1]) { case '/': case '\\': sprintf(path, "%s*", dir); break; default: sprintf(path, "%s%c*", dir, GF_PATH_SEPARATOR); break; } #else strcpy(path, dir); if (path[strlen(path)-1] != '/') strcat(path, "/"); #endif #ifdef WIN32 SearchH= FindFirstFile(path, &FindData); if (SearchH == INVALID_HANDLE_VALUE) return GF_IO_ERR; #if defined (_WIN32_WCE) _path[strlen(_path)-1] = 0; #else path[strlen(path)-1] = 0; #endif while (SearchH != INVALID_HANDLE_VALUE) { #else the_dir = opendir(path); if (the_dir == NULL) { GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("[Core] Cannot open directory %s for enumeration\n", path)); return GF_IO_ERR; } the_file = readdir(the_dir); while (the_file) { #endif memset(&file_info, 0, sizeof(GF_FileEnumInfo) ); #if defined (_WIN32_WCE) if (!wcscmp(FindData.cFileName, _T(".") )) goto next; if (!wcscmp(FindData.cFileName, _T("..") )) goto next; #elif defined(WIN32) if (!strcmp(FindData.cFileName, ".")) goto next; if (!strcmp(FindData.cFileName, "..")) goto next; #else if (!strcmp(the_file->d_name, "..")) goto next; if (the_file->d_name[0] == '.') goto next; #endif #ifdef WIN32 file_info.directory = (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? GF_TRUE : GF_FALSE; if (!enum_directory && file_info.directory) goto next; if (enum_directory && !file_info.directory) goto next; #endif if (filter) { #if defined (_WIN32_WCE) short ext[30]; short *sep = wcsrchr(FindData.cFileName, (wchar_t) '.'); if (!sep) goto next; wcscpy(ext, sep+1); wcslwr(ext); if (!wcsstr(w_filter, ext)) goto next; #elif defined(WIN32) char ext[30]; char *sep = strrchr(FindData.cFileName, '.'); if (!sep) goto next; strcpy(ext, sep+1); strlwr(ext); if (!strstr(filter, ext)) goto next; #else char ext[30]; char *sep = strrchr(the_file->d_name, '.'); if (!sep) goto next; strcpy(ext, sep+1); strlwr(ext); if (!strstr(filter, sep+1)) goto next; #endif } #if defined(WIN32) file_info.hidden = (FindData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) ? 1 : 0; file_info.system = (FindData.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) ? 1 : 0; file_info.size = MAXDWORD; file_info.size += 1; file_info.size *= FindData.nFileSizeHigh; file_info.size += FindData.nFileSizeLow; file_info.last_modified = (u64) ((*(LONGLONG *) &FindData.ftLastWriteTime - TIMESPEC_TO_FILETIME_OFFSET) / 10000000); #endif #if defined (_WIN32_WCE) CE_WideToChar(FindData.cFileName, file); strcpy(item_path, _path); strcat(item_path, file); #elif defined(WIN32) strcpy(item_path, path); strcat(item_path, FindData.cFileName); file = FindData.cFileName; #else strcpy(item_path, path); strcat(item_path, the_file->d_name); GF_LOG(GF_LOG_DEBUG, GF_LOG_CORE, ("[Core] Checking file %s for enum\n", item_path)); if (stat( item_path, &st ) != 0) goto next; file_info.directory = ((st.st_mode & S_IFMT) == S_IFDIR) ? GF_TRUE : GF_FALSE; if (enum_directory && !file_info.directory) goto next; if (!enum_directory && file_info.directory) goto next; file_info.size = st.st_size; { struct tm _t = * gmtime(& st.st_mtime); file_info.last_modified = mktime(&_t); } file = the_file->d_name; if (file && file[0]=='.') file_info.hidden = 1; if (file_info.directory) { char * parent_name = strrchr(item_path, '/'); if (!parent_name) { file_info.drive = GF_TRUE; } else { struct stat st_parent; parent_name[0] = 0; if (stat(item_path, &st_parent) == 0) { if ((st.st_dev != st_parent.st_dev) || ((st.st_dev == st_parent.st_dev) && (st.st_ino == st_parent.st_ino))) { file_info.drive = GF_TRUE; } } parent_name[0] = '/'; } } #endif if (enum_dir_fct(cbck, file, item_path, &file_info)) { #ifdef WIN32 BOOL ret = FindClose(SearchH); if (!ret) { DWORD err = GetLastError(); GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("[core] FindClose() in gf_enum_directory() returned(1) the following error code: %d\n", err)); } #endif break; } next: #ifdef WIN32 if (!FindNextFile(SearchH, &FindData)) { BOOL ret = FindClose(SearchH); if (!ret) { DWORD err = GetLastError(); GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("[core] FindClose() in gf_enum_directory() returned(2) the following error code: %d\n", err)); } break; } #else the_file = readdir(the_dir); #endif } #ifndef WIN32 closedir(the_dir); #endif return GF_OK; } GF_EXPORT u64 gf_f64_tell(FILE *fp) { #if defined(_WIN32_WCE) return (u64) ftell(fp); #elif defined(GPAC_CONFIG_WIN32) /* mingw or cygwin */ #if (_FILE_OFFSET_BITS >= 64) return (u64) ftello64(fp); #else return (u64) ftell(fp); #endif #elif defined(WIN32) return (u64) _ftelli64(fp); #elif defined(GPAC_CONFIG_LINUX) && !defined(GPAC_ANDROID) return (u64) ftello64(fp); #elif (defined(GPAC_CONFIG_FREEBSD) || defined(GPAC_CONFIG_DARWIN)) return (u64) ftello(fp); #else return (u64) ftell(fp); #endif } GF_EXPORT u64 gf_f64_seek(FILE *fp, s64 offset, s32 whence) { #if defined(_WIN32_WCE) return (u64) fseek(fp, (s32) offset, whence); #elif defined(GPAC_CONFIG_WIN32) /* mingw or cygwin */ #if (_FILE_OFFSET_BITS >= 64) return (u64) fseeko64(fp, offset, whence); #else return (u64) fseek(fp, (s32) offset, whence); #endif #elif defined(WIN32) return (u64) _fseeki64(fp, offset, whence); #elif defined(GPAC_CONFIG_LINUX) && !defined(GPAC_ANDROID) return fseeko64(fp, (off64_t) offset, whence); #elif (defined(GPAC_CONFIG_FREEBSD) || defined(GPAC_CONFIG_DARWIN)) return fseeko(fp, (off_t) offset, whence); #else return fseek(fp, (s32) offset, whence); #endif } GF_EXPORT FILE *gf_f64_open(const char *file_name, const char *mode) { #if defined(WIN32) FILE *res = fopen(file_name, mode); if (res) return res; if (strchr(mode, 'w') || strchr(mode, 'a')) { u32 err = GetLastError(); GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("[Win32] system failure for file opening of %s in mode %s: 0x%08x\n", file_name, mode, err)); } return NULL; #elif defined(GPAC_CONFIG_LINUX) && !defined(GPAC_ANDROID) return fopen64(file_name, mode); #elif (defined(GPAC_CONFIG_FREEBSD) || defined(GPAC_CONFIG_DARWIN)) return fopen(file_name, mode); #else return fopen(file_name, mode); #endif }