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); } } }
void COptDecoder::SaveOptions() { COsmo4 *gpac = GetApp(); TCHAR wstr[100]; char str[100]; m_Audio.GetWindowText(wstr, 50); CE_WideToChar((u16 *)wstr, str); gf_cfg_set_key(gpac->m_user.config, "Systems", "DefAudioDec", str); m_Video.GetWindowText(wstr, 50); CE_WideToChar((u16 *)wstr, str); gf_cfg_set_key(gpac->m_user.config, "Systems", "DefVideoDec", str); }
void COptFont::SaveOptions() { COsmo4 *gpac = GetApp(); char str[MAX_PATH]; TCHAR wstr[MAX_PATH]; m_Fonts.GetWindowText(wstr, 50); CE_WideToChar((u16 *)wstr, str); gf_cfg_set_key(gpac->m_user.config, "FontEngine", "FontReader", str); m_BrowseFont.GetWindowText(wstr, 50); CE_WideToChar((u16 *)wstr, str); gf_cfg_set_key(gpac->m_user.config, "FontEngine", "FontDirectory", str); gf_cfg_set_key(gpac->m_user.config, "Compositor", "TextureTextMode", m_UseTexture.GetCheck() ? "Default" : "Never"); }
void OpenDlg::OnOK() { CString URL; char szUrl[5000]; int sel = m_URLs.GetCurSel(); if (sel == CB_ERR) { m_URLs.GetWindowText(URL); } else { m_URLs.GetLBText(sel, URL); } if (!URL.GetLength()) { EndDialog(IDCANCEL); return; } COsmo4 *app = GetApp(); u32 nb_entries; app->m_filename = URL; CE_WideToChar((unsigned short *) (LPCTSTR) URL, szUrl); gf_cfg_set_key(app->m_user.config, "RecentFiles", szUrl, NULL); gf_cfg_insert_key(app->m_user.config, "RecentFiles", szUrl, "", 0); /*remove last entry if needed*/ nb_entries = gf_cfg_get_key_count(app->m_user.config, "RecentFiles"); if (nb_entries>20) { gf_cfg_set_key(app->m_user.config, "RecentFiles", gf_cfg_get_key_name(app->m_user.config, "RecentFiles", nb_entries-1), NULL); } EndDialog(IDOK); }
void COptStream::SaveOptions() { COsmo4 *gpac = GetApp(); Bool force_rtsp = 0; s32 sel = m_Port.GetCurSel(); switch (sel) { case 3: gf_cfg_set_key(gpac->m_user.config, "Streaming", "DefaultPort", "8080"); force_rtsp = 1; break; case 2: gf_cfg_set_key(gpac->m_user.config, "Streaming", "DefaultPort", "80"); force_rtsp = 1; break; case 1: gf_cfg_set_key(gpac->m_user.config, "Streaming", "DefaultPort", "7070"); break; default: gf_cfg_set_key(gpac->m_user.config, "Streaming", "DefaultPort", "554"); break; } if (force_rtsp) { gf_cfg_set_key(gpac->m_user.config, "Streaming", "RTPoverRTSP", "yes"); } else { gf_cfg_set_key(gpac->m_user.config, "Streaming", "RTPoverRTSP", m_UseRTSP.GetCheck() ? "yes" : "no"); if (!m_UseRTSP.GetCheck()) gf_cfg_set_key(gpac->m_user.config, "Streaming", "ReorderSize", m_Reorder.GetCheck() ? "30" : "0"); } TCHAR wstr[50]; char str[50]; m_Timeout.GetWindowText(wstr, 50); CE_WideToChar((u16 *)wstr, str); gf_cfg_set_key(gpac->m_user.config, "Streaming", "RTSPTimeout", str); m_Buffer.GetWindowText(wstr, 50); CE_WideToChar((u16 *)wstr, str); gf_cfg_set_key(gpac->m_user.config, "Network", "BufferLength", str); if (m_Rebuffer.GetCheck()) { m_RebufferLen.GetWindowText(wstr, 50); CE_WideToChar((u16 *)wstr, str); gf_cfg_set_key(gpac->m_user.config, "Network", "RebufferLength", str); } else { gf_cfg_set_key(gpac->m_user.config, "Network", "RebufferLength", "0"); } }
void COptStream::CheckRebuffer() { TCHAR wstr[50]; char str[50]; s32 buf, rebuf; m_Buffer.GetWindowText(wstr, 50); CE_WideToChar((u16 *)wstr, str); buf = atoi(str); m_RebufferLen.GetWindowText(wstr, 50); CE_WideToChar((u16 *)wstr, str); rebuf = atoi(str); if (rebuf*2 > buf) { rebuf = buf/2; wsprintf(wstr, _T("%d"), rebuf); m_RebufferLen.SetWindowText(wstr); } }
void COptHTTP::SaveOptions() { TCHAR wTmp[500]; char szCacheDir[500]; COsmo4 *gpac = GetApp(); gf_cfg_set_key(gpac->m_user.config, "Downloader", "CleanCache", m_CleanCache.GetCheck() ? "yes" : "no"); gf_cfg_set_key(gpac->m_user.config, "Downloader", "RestartFiles", m_RestartFile.GetCheck() ? "yes" : "no"); gf_cfg_set_key(gpac->m_user.config, "SAXLoader", "Progressive", m_Progressive.GetCheck() ? "yes" : "no"); m_SaxDuration.GetWindowText(wTmp, MAX_PATH); CE_WideToChar((u16 *)wTmp, szCacheDir); gf_cfg_set_key(gpac->m_user.config, "SAXLoader", "MaxDuration", szCacheDir); m_CacheDir.GetWindowText(wTmp, MAX_PATH); CE_WideToChar((u16 *)wTmp, szCacheDir); gf_cfg_set_key(gpac->m_user.config, "General", "CacheDirectory", szCacheDir); }
void COptGen::OnFileassoc() { HKEY hSection; TCHAR szDir[MAX_PATH]; char szTemp[MAX_PATH]; TCHAR cmd[MAX_PATH]; DWORD ioSize = MAX_PATH; DWORD dwDisp; RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Osmo4"), 0, KEY_READ, &hSection); GetModuleFileName(NULL, szDir, MAX_PATH); while (szDir[strlen((char *) szDir)-1] != (TCHAR) '\\') szDir[strlen((char *) szDir)-1] = 0; if (!hSection) RegCreateKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Osmo4"), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hSection, &dwDisp); CE_WideToChar((u16 *)szDir, szTemp); /*overwrite install dir with current path*/ RegSetValueEx(hSection, _T("Install_Dir"), 0, REG_SZ, (const unsigned char *) szTemp, strlen(szTemp)+1); RegCloseKey(hSection); /*overwrite .mp4 file associations */ RegCreateKeyEx(HKEY_CLASSES_ROOT, _T("mp4file\\DefaultIcon"), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hSection, &dwDisp); wcscpy(cmd, szDir); wcscat(cmd, _T("Osmo4.ico") ); CE_WideToChar((u16 *)cmd, szTemp); RegSetValueEx(hSection, _T(""), 0, REG_SZ, (const unsigned char *) szTemp, strlen((const char *) szTemp)+1); RegCloseKey(hSection); RegCreateKeyEx(HKEY_CLASSES_ROOT, _T("mp4file\\Shell\\open\\command"), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hSection, &dwDisp); wcscpy(cmd, szDir); wcscat(cmd, _T("Osmo4.exe \"%L\"") ); CE_WideToChar((u16 *)cmd, szTemp); RegSetValueEx(hSection, _T(""), 0, REG_SZ, (const unsigned char *) szTemp, strlen(szTemp)+1); RegCloseKey(hSection); RegCreateKeyEx(HKEY_CLASSES_ROOT, _T(".mp4"), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hSection, &dwDisp); RegSetValueEx(hSection, _T(""), 0, REG_SZ, (const unsigned char *) "mp4file", strlen("mp4file")+1); RegCloseKey(hSection); }
void COptAudio::SaveOptions() { COsmo4 *gpac = GetApp(); TCHAR wstr[50]; char str[50]; gf_cfg_set_key(gpac->m_user.config, "Audio", "ForceConfig", m_ForceConfig.GetCheck() ? "yes" : "no"); gf_cfg_set_key(gpac->m_user.config, "Audio", "NoResync", m_AudioResync.GetCheck() ? "yes" : "no"); m_AudioEdit.GetWindowText(wstr, 20); CE_WideToChar((u16 *)wstr, str); gf_cfg_set_key(gpac->m_user.config, "Audio", "NumBuffers", str); m_AudioDur.GetWindowText(wstr, 20); CE_WideToChar((u16 *)wstr, str); gf_cfg_set_key(gpac->m_user.config, "Audio", "TotalDuration", str); m_DriverList.GetWindowText(wstr, 50); CE_WideToChar((u16 *)wstr, str); gf_cfg_set_key(gpac->m_user.config, "Audio", "DriverName", str); }
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; }
LONG CMainFrame::Open(WPARAM wParam, LPARAM lParam) { COsmo4 *app = GetApp(); CloseURL(); char filename[5000]; CE_WideToChar((LPTSTR) (LPCTSTR) app->m_filename, filename); app->m_stoped = 0; if (app->m_reconnect_time) { gf_term_connect_from_time(app->m_term, filename, app->m_reconnect_time, 0); app->m_reconnect_time = 0; } else { gf_term_connect(app->m_term, filename); } app->SetBacklightState(1); return 1; }
void CMainFrame::OnFilePause() { COsmo4 *app = GetApp(); if (app->m_stoped) { char filename[5000]; CE_WideToChar((LPTSTR) (LPCTSTR) app->m_filename, filename); app->m_stoped = 0; gf_term_connect(app->m_term, filename); app->SetBacklightState(1); if (m_view_timing) SetTimer(PROGRESS_TIMER, PROGRESS_REFRESH_MS, ProgressTimer); SetPauseButton(); } else { app->Pause(); } }
/*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; }
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(); }
void set_directory(TCHAR *dir) { SendMessage(hList, LB_RESETCONTENT, 0, 0); CE_WideToChar((u16 *) dir, (char *) current_dir); wcscpy(w_current_dir, dir); SetWindowText(hDirTxt, w_current_dir); if (strcmp((const char *) current_dir, "\\")) { int iRes = SendMessage(hList, LB_ADDSTRING, 0, (LPARAM)(LPCTSTR) _T("+ ..") ); SendMessage(hList, LB_SETITEMDATA, iRes, (LPARAM) 1); } /*enum directories*/ gf_enum_directory((const char *) current_dir, GF_TRUE, enum_dirs, NULL, NULL); /*enum files*/ gf_enum_directory((char *) current_dir, GF_FALSE, enum_files, NULL, NULL); SendMessage(hList, LB_SETCURSEL, 0, 0); SetFocus(hList); }
BOOL COsmo4::InitInstance() { if (!AfxSocketInit()) { AfxMessageBox(IDP_SOCKETS_INIT_FAILED); return FALSE; } gf_sys_init(); SetRegistryKey(_T("GPAC")); m_prev_batt_bl = m_prev_ac_bl = 0; m_screen_width = GetSystemMetrics(SM_CXSCREEN); m_screen_height = GetSystemMetrics(SM_CYSCREEN); m_menu_height = GetSystemMetrics(SM_CYMENU); m_scene_width = m_scene_height = 0; CMainFrame* pFrame = new CMainFrame; m_pMainWnd = pFrame; pFrame->LoadFrame(IDR_MAINFRAME, WS_VISIBLE, NULL, NULL); pFrame->ShowWindow(m_nCmdShow); pFrame->UpdateWindow(); char config_path[MAX_PATH]; CE_WideToChar((unsigned short *) (LPCTSTR) AfxGetApp()->m_pszHelpFilePath, (char *) config_path); while (config_path[strlen((char *) config_path)-1] != '\\') config_path[strlen((char *) config_path)-1] = 0; /*setup user*/ memset(&m_user, 0, sizeof(GF_User)); /*init config and plugins*/ m_user.config = gf_cfg_new((const char *) config_path, "GPAC.cfg"); if (!m_user.config) { /*create blank config file in the exe dir*/ unsigned char config_file[MAX_PATH]; strcpy((char *) config_file, (const char *) config_path); strcat((char *) config_file, "GPAC.cfg"); FILE *ft = fopen((const char *) config_file, "wt"); fclose(ft); m_user.config = gf_cfg_new((const char *) config_path, "GPAC.cfg"); if (!m_user.config) { MessageBox(NULL, _T("GPAC Configuration file not found"), _T("Fatal Error"), MB_OK); m_pMainWnd->PostMessage(WM_CLOSE); } } const char *str = gf_cfg_get_key(m_user.config, "General", "LogLevel"); EnableLogs((str && !strcmp(str, "debug")) ? 1 : 0); str = gf_cfg_get_key(m_user.config, "General", "ModulesDirectory"); m_user.modules = gf_modules_new(str, m_user.config); if (!m_user.modules) { unsigned char str_path[MAX_PATH]; const char *sOpt; /*inital launch*/ m_user.modules = gf_modules_new(config_path, m_user.config); if (m_user.modules) { gf_cfg_set_key(m_user.config, "General", "ModulesDirectory", (const char *) config_path); gf_cfg_set_key(m_user.config, "Rendering", "RendererName", "GPAC 2D Renderer"); sOpt = gf_cfg_get_key(m_user.config, "Rendering", "Raster2D"); if (!sOpt) gf_cfg_set_key(m_user.config, "Rendering", "Raster2D", "GPAC 2D Raster"); sOpt = gf_cfg_get_key(m_user.config, "General", "CacheDirectory"); if (!sOpt) { sprintf((char *) str_path, "%scache", config_path); gf_cfg_set_key(m_user.config, "General", "CacheDirectory", (const char *) str_path); } /*setup UDP traffic autodetect*/ gf_cfg_set_key(m_user.config, "Network", "AutoReconfigUDP", "yes"); gf_cfg_set_key(m_user.config, "Network", "UDPNotAvailable", "no"); gf_cfg_set_key(m_user.config, "Network", "UDPTimeout", "10000"); gf_cfg_set_key(m_user.config, "Network", "BufferLength", "3000"); /*first launch, register all files ext*/ u32 i; for (i=0; i<gf_modules_get_count(m_user.modules); i++) { GF_InputService *ifce = (GF_InputService *) gf_modules_load_interface(m_user.modules, i, GF_NET_CLIENT_INTERFACE); if (!ifce) continue; if (ifce) { ifce->CanHandleURL(ifce, "test.test"); gf_modules_close_interface((GF_BaseInterface *)ifce); } } } /*check audio config on windows, force config*/ sOpt = gf_cfg_get_key(m_user.config, "Audio", "ForceConfig"); if (!sOpt) { gf_cfg_set_key(m_user.config, "Audio", "ForceConfig", "yes"); gf_cfg_set_key(m_user.config, "Audio", "NumBuffers", "2"); gf_cfg_set_key(m_user.config, "Audio", "TotalDuration", "200"); } /*by default use GDIplus, much faster than freetype on font loading*/ gf_cfg_set_key(m_user.config, "FontEngine", "DriverName", "ft_font"); sprintf((char *) str_path, "%sgpac.mp4", config_path); gf_cfg_set_key(m_user.config, "General", "StartupFile", (const char *) str_path); ::MessageBox(NULL, _T("Osmo4/GPAC Setup complete"), _T("Initial launch"), MB_OK); } if (! gf_modules_get_count(m_user.modules) ) { MessageBox(NULL, _T("No plugins available - system cannot work"), _T("Fatal Error"), MB_OK); m_pMainWnd->PostMessage(WM_QUIT); } /*setup font dir*/ str = gf_cfg_get_key(m_user.config, "FontEngine", "FontDirectory"); if (!str || !strlen(str) ) { strcpy((char *) config_path, "\\Windows"); gf_cfg_set_key(m_user.config, "FontEngine", "FontDirectory", (const char *) config_path); } /*work with iPaq's default fonts ...*/ str = gf_cfg_get_key(m_user.config, "FontEngine", "FontSerif"); if (!str) gf_cfg_set_key(m_user.config, "FontEngine", "FontSerif", "Tahoma"); str = gf_cfg_get_key(m_user.config, "FontEngine", "FontSans"); if (!str) gf_cfg_set_key(m_user.config, "FontEngine", "FontSans", "Frutiger"); str = gf_cfg_get_key(m_user.config, "FontEngine", "FontFixed"); if (!str) gf_cfg_set_key(m_user.config, "FontEngine", "FontFixed", "Courier New"); /*check video driver, if none or raw_out use dx_hw by default*/ str = gf_cfg_get_key(m_user.config, "Video", "DriverName"); if (!str || !stricmp(str, "raw_out")) { gf_cfg_set_key(m_user.config, "Video", "DriverName", "gapi"); } m_user.config = m_user.config; m_user.modules = m_user.modules; m_user.EventProc = Osmo4CE_EventProc; m_user.opaque = this; m_user.os_window_handler = pFrame->m_wndView.m_hWnd; m_term = gf_term_new(&m_user); if (! m_term) { MessageBox(NULL, _T("Cannot load MPEG-4 Terminal"), _T("Fatal Error"), MB_OK); m_pMainWnd->PostMessage(WM_QUIT); } m_stoped = 0; m_open = 0; m_can_seek = 0; m_DoResume = 0; SetOptions(); pFrame->SendMessage(WM_SETSIZE, 0, 0); ShowTaskBar(0); CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); if (! cmdInfo.m_strFileName.IsEmpty()) { m_filename = cmdInfo.m_strFileName; m_pMainWnd->PostMessage(WM_OPENURL); } else { str = gf_cfg_get_key(m_user.config, "General", "StartupFile"); if (str) gf_term_connect(m_term, str); } return TRUE; }
static Bool get_default_install_path(char *file_path, u32 path_type) { FILE *f; char *sep; char szPath[GF_MAX_PATH]; #ifdef _WIN32_WCE TCHAR w_szPath[GF_MAX_PATH]; GetModuleFileName(NULL, w_szPath, GF_MAX_PATH); CE_WideToChar((u16 *) w_szPath, file_path); #else GetModuleFileNameA(NULL, file_path, GF_MAX_PATH); #endif /*remove exe name*/ if (strstr(file_path, ".exe")) { sep = strrchr(file_path, '\\'); if (sep) sep[0] = 0; } strcpy(szPath, file_path); strlwr(szPath); /*if this is run from a browser, we do not get our app path - fortunately on Windows, we always use 'GPAC' in the installation path*/ if (!strstr(file_path, "gpac") && !strstr(file_path, "GPAC") ) { HKEY hKey = NULL; DWORD dwSize = GF_MAX_PATH; /*locate the key in current user, then in local machine*/ #ifdef _WIN32_WCE DWORD dwType = REG_SZ; u16 w_path[1024]; RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Software\\GPAC"), 0, KEY_READ, &hKey); #ifdef _DEBUG if (RegQueryValueEx(hKey, TEXT("DebugDir"), 0, &dwType, (LPBYTE) w_path, &dwSize) != ERROR_SUCCESS) #endif RegQueryValueEx(hKey, TEXT("InstallDir"), 0, &dwType, (LPBYTE) w_path, &dwSize); CE_WideToChar(w_path, (char *)file_path); RegCloseKey(hKey); #else if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\GPAC", 0, KEY_READ, &hKey) != ERROR_SUCCESS) RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\GPAC", 0, KEY_READ, &hKey); dwSize = GF_MAX_PATH; #ifdef _DEBUG if (RegQueryValueEx(hKey, "DebugDir", NULL, NULL,(unsigned char*) file_path, &dwSize) != ERROR_SUCCESS) #endif RegQueryValueEx(hKey, "InstallDir", NULL, NULL,(unsigned char*) file_path, &dwSize); RegCloseKey(hKey); #endif } if (path_type==GF_PATH_APP) return GF_TRUE; if (path_type==GF_PATH_GUI) { char *sep; strcat(file_path, "\\gui"); if (check_file_exists("gui.bt", file_path, file_path)) return GF_TRUE; sep = strstr(file_path, "\\bin\\"); if (sep) { sep[0] = 0; strcat(file_path, "\\gui"); if (check_file_exists("gui.bt", file_path, file_path)) return GF_TRUE; } return GF_FALSE; } /*modules are stored in the GPAC directory (should be changed to GPAC/modules)*/ if (path_type==GF_PATH_MODULES) return GF_TRUE; /*we are looking for the config file path - make sure it is writable*/ assert(path_type == GF_PATH_CFG); strcpy(szPath, file_path); strcat(szPath, "\\gpaccfgtest.txt"); //do not use gf_fopen here, we don't want to through any error if failure f = fopen(szPath, "wb"); if (f != NULL) { fclose(f); gf_delete_file(szPath); return GF_TRUE; } #ifdef _WIN32_WCE return 0; #else /*no write access, get user home directory*/ SHGetFolderPath(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, file_path); if (file_path[strlen(file_path)-1] != '\\') strcat(file_path, "\\"); strcat(file_path, "GPAC"); /*create GPAC dir*/ _mkdir(file_path); strcpy(szPath, file_path); strcat(szPath, "\\gpaccfgtest.txt"); f = fopen(szPath, "wb"); /*COMPLETE FAILURE*/ if (!f) return GF_FALSE; fclose(f); gf_delete_file(szPath); return GF_TRUE; #endif }
/*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) { #ifdef WIN32 wchar_t item_path[GF_MAX_PATH]; #else char item_path[GF_MAX_PATH]; #endif 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]; #elif defined(WIN32) wchar_t path[GF_MAX_PATH], *file; wchar_t w_filter[GF_MAX_PATH]; wchar_t w_dir[GF_MAX_PATH]; char *mbs_file, *mbs_item_path; #else char path[GF_MAX_PATH], *file; #endif #ifdef WIN32 WIN32_FIND_DATAW 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 = (char*)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) { const char* tmpdir = dir; gf_utf8_mbstowcs(w_dir, sizeof(w_dir), &tmpdir); } switch (w_dir[wcslen(w_dir) - 1]) { case '/': case '\\': swprintf(path, MAX_PATH, L"%s*", w_dir); break; default: swprintf(path, MAX_PATH, L"%s%c*", w_dir, GF_PATH_SEPARATOR); break; } { const char* tmpfilter = filter; gf_utf8_mbstowcs(w_filter, sizeof(w_filter), &tmpfilter); } #else strcpy(path, dir); if (path[strlen(path)-1] != '/') strcat(path, "/"); #endif #ifdef WIN32 SearchH= FindFirstFileW(path, &FindData); if (SearchH == INVALID_HANDLE_VALUE) return GF_IO_ERR; #if defined (_WIN32_WCE) _path[strlen(_path)-1] = 0; #else path[wcslen(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: %d\n", path, errno)); 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 (!wcscmp(FindData.cFileName, L".")) goto next; if (!wcscmp(FindData.cFileName, L"..")) 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) wchar_t ext[30]; wchar_t *sep = wcsrchr(FindData.cFileName, L'.'); if (!sep) goto next; wcscpy(ext, sep+1); wcslwr(ext); if (!wcsstr(w_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) ? GF_TRUE : GF_FALSE; file_info.system = (FindData.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) ? GF_TRUE : GF_FALSE; 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) wcscpy(item_path, path); wcscat(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 #ifdef WIN32 mbs_file = wcs_to_utf8(file); mbs_item_path = wcs_to_utf8(item_path); if (!mbs_file || !mbs_item_path) { if (mbs_file) gf_free(mbs_file); if (mbs_item_path) gf_free(mbs_item_path); return GF_IO_ERR; } if (enum_dir_fct(cbck, mbs_file, mbs_item_path, &file_info)) { 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)); } #else if (enum_dir_fct(cbck, file, item_path, &file_info)) { #endif break; } #ifdef WIN32 gf_free(mbs_file); gf_free(mbs_item_path); #endif next: #ifdef WIN32 if (!FindNextFileW(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_ftell(FILE *fp) { #if defined(_WIN32_WCE) return (u64) ftell(fp); #elif defined(GPAC_CONFIG_WIN32) && !defined(__CYGWIN__) /* 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_fseek(FILE *fp, s64 offset, s32 whence) { #if defined(_WIN32_WCE) return (u64) fseek(fp, (s32) offset, whence); #elif defined(GPAC_CONFIG_WIN32) && !defined(__CYGWIN__) /* 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_fopen(const char *file_name, const char *mode) { FILE *res = NULL; #if defined(WIN32) wchar_t *wname; wchar_t *wmode; wname = utf8_to_wcs(file_name); wmode = utf8_to_wcs(mode); if (!wname || !wmode) { if (wname) gf_free(wname); if (wmode) gf_free(wmode); return NULL; } res = _wfsopen(wname, wmode, _SH_DENYNO); gf_free(wname); gf_free(wmode); #elif defined(GPAC_CONFIG_LINUX) && !defined(GPAC_ANDROID) res = fopen64(file_name, mode); #elif (defined(GPAC_CONFIG_FREEBSD) || defined(GPAC_CONFIG_DARWIN)) res = fopen(file_name, mode); #else res = fopen(file_name, mode); #endif if (res) { gpac_file_handles++; GF_LOG(GF_LOG_DEBUG, GF_LOG_CORE, ("[Core] file %s opened in mode %s - %d file handles\n", file_name, mode, gpac_file_handles)); } else { if (strchr(mode, 'w') || strchr(mode, 'a')) { #if defined(WIN32) u32 err = GetLastError(); GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("[Core] system failure for file opening of %s in mode %s: 0x%08x\n", file_name, mode, err)); #else GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("[Core] system failure for file opening of %s in mode %s: %d\n", file_name, mode, errno)); #endif } } return res; } GF_EXPORT s32 gf_fclose(FILE *file) { if (file) { assert(gpac_file_handles); gpac_file_handles--; } return fclose(file); } #if (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! defined(_GNU_SOURCE) && !defined(WIN32) #define HAVE_STRERROR_R 1 #endif GF_EXPORT size_t gf_fread(void *ptr, size_t size, size_t nmemb, FILE *stream) { return fread(ptr, size, nmemb, stream); } GF_EXPORT size_t gf_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) { size_t result = fwrite(ptr, size, nmemb, stream); if (result != nmemb) { #ifdef _WIN32_WCE GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("Error writing data: %d blocks to write but %d blocks written\n", nmemb, result)); #else #if defined WIN32 && !defined(GPAC_CONFIG_WIN32) errno_t errno_save; _get_errno(&errno_save); #else int errno_save = errno; #endif //if (errno_save!=0) { #ifdef HAVE_STRERROR_R #define ERRSTR_BUF_SIZE 256 char errstr[ERRSTR_BUF_SIZE]; if(strerror_r(errno_save, errstr, ERRSTR_BUF_SIZE) != 0) { strerror_r(0, errstr, ERRSTR_BUF_SIZE); } #else char *errstr = (char*)strerror(errno_save); #endif GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("Error writing data (%s): %d blocks to write but %d blocks written\n", errstr, nmemb, result)); } #endif } return result; }
/*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 }
BOOL COsmo4::InitInstance() { Bool first_load = 0; if (!AfxSocketInit()) { AfxMessageBox(IDP_SOCKETS_INIT_FAILED); return FALSE; } gf_sys_init(); SetRegistryKey(_T("GPAC")); m_prev_batt_bl = m_prev_ac_bl = 0; m_screen_width = GetSystemMetrics(SM_CXSCREEN); m_screen_height = GetSystemMetrics(SM_CYSCREEN); m_menu_height = GetSystemMetrics(SM_CYMENU); m_scene_width = m_scene_height = 0; CMainFrame* pFrame = new CMainFrame; m_pMainWnd = pFrame; pFrame->LoadFrame(IDR_MAINFRAME, WS_VISIBLE, NULL, NULL); pFrame->ShowWindow(m_nCmdShow); pFrame->UpdateWindow(); TCHAR w_config_path[MAX_PATH]; char config_path[MAX_PATH]; GetModuleFileName(NULL, w_config_path, MAX_PATH); CE_WideToChar((u16 *) w_config_path, (char *) config_path); while (config_path[strlen((char *) config_path)-1] != '\\') config_path[strlen((char *) config_path)-1] = 0; /*setup user*/ memset(&m_user, 0, sizeof(GF_User)); /*init config and plugins*/ m_user.config = gf_cfg_init(NULL, &first_load); if (!m_user.config) { MessageBox(NULL, _T("GPAC Configuration file not found"), _T("Fatal Error"), MB_OK); m_pMainWnd->PostMessage(WM_CLOSE); } const char *str = gf_cfg_get_key(m_user.config, "General", "LogLevel"); EnableLogs((str && !strcmp(str, "debug")) ? 1 : 0); if (first_load) { /*first launch, register all files ext*/ u32 i; for (i=0; i<gf_modules_get_count(m_user.modules); i++) { GF_InputService *ifce = (GF_InputService *) gf_modules_load_interface(m_user.modules, i, GF_NET_CLIENT_INTERFACE); if (!ifce) continue; if (ifce) { ifce->CanHandleURL(ifce, "test.test"); gf_modules_close_interface((GF_BaseInterface *)ifce); } } ::MessageBox(NULL, _T("Osmo4/GPAC Setup complete"), _T("Initial launch"), MB_OK); } str = gf_cfg_get_key(m_user.config, "General", "ModulesDirectory"); m_user.modules = gf_modules_new(str, m_user.config); if (!m_user.modules || ! gf_modules_get_count(m_user.modules) ) { MessageBox(NULL, _T("No plugins available - system cannot work"), _T("Fatal Error"), MB_OK); m_pMainWnd->PostMessage(WM_QUIT); return FALSE; } m_user.config = m_user.config; m_user.modules = m_user.modules; m_user.EventProc = Osmo4CE_EventProc; m_user.opaque = this; m_user.os_window_handler = pFrame->m_wndView.m_hWnd; m_term = gf_term_new(&m_user); if (! m_term) { MessageBox(NULL, _T("Cannot load MPEG-4 Terminal"), _T("Fatal Error"), MB_OK); m_pMainWnd->PostMessage(WM_QUIT); } m_stopped = 0; m_open = 0; m_can_seek = 0; m_DoResume = 0; SetOptions(); pFrame->SendMessage(WM_SETSIZE, 0, 0); ShowTaskBar(0); CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); if (! cmdInfo.m_strFileName.IsEmpty()) { m_filename = cmdInfo.m_strFileName; m_pMainWnd->PostMessage(WM_OPENURL); } else { str = gf_cfg_get_key(m_user.config, "General", "StartupFile"); if (str) gf_term_connect(m_term, str); } return TRUE; }