LRESULT CMainWindow::OnAlertShowPopup (UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/) { //LOG(INFO) + __FUNCTION__; StringW strAppName = RHODESAPP().getAppNameW(); CAlertDialog::Params *params = (CAlertDialog::Params *)lParam; if (params->m_dlgType == CAlertDialog::Params::DLG_STATUS) { m_SyncStatusDlg.setStatusText(convertToStringW(params->m_message).c_str()); m_SyncStatusDlg.setTitle( convertToStringW(params->m_title).c_str() ); if ( !m_SyncStatusDlg.m_hWnd ) m_SyncStatusDlg.Create(m_hWnd, 0); else { m_SyncStatusDlg.ShowWindow(SW_SHOW); m_SyncStatusDlg.BringWindowToTop(); } }else if (params->m_dlgType == CAlertDialog::Params::DLG_DEFAULT) { MessageBox(convertToStringW(params->m_message).c_str(), strAppName.c_str(), MB_ICONWARNING | MB_OK); RHODESAPP().callPopupCallback(params->m_callback, "ok", "ok"); } else if (params->m_dlgType == CAlertDialog::Params::DLG_CUSTOM) { if ( params->m_buttons.size() == 1 && strcasecmp(params->m_buttons[0].m_strCaption.c_str(), "ok") == 0) { MessageBox(convertToStringW(params->m_message).c_str(), convertToStringW(params->m_title).c_str(), MB_ICONWARNING | MB_OK); RHODESAPP().callPopupCallback(params->m_callback, params->m_buttons[0].m_strID, params->m_buttons[0].m_strCaption); } else if (params->m_buttons.size() == 2 && strcasecmp(params->m_buttons[0].m_strCaption.c_str(), "ok") == 0 && strcasecmp(params->m_buttons[1].m_strCaption.c_str(), "cancel") == 0) { int nRes = MessageBox(convertToStringW(params->m_message).c_str(), convertToStringW(params->m_title).c_str(), MB_ICONWARNING | MB_OKCANCEL); int nBtn = nRes == IDCANCEL ? 1 : 0; RHODESAPP().callPopupCallback(params->m_callback, params->m_buttons[nBtn].m_strID, params->m_buttons[nBtn].m_strCaption); } else { if (m_alertDialog == NULL) { m_alertDialog = new CAlertDialog(params); m_alertDialog->DoModal(); delete m_alertDialog; m_alertDialog = NULL; } else { LOG(WARNING) + "Trying to show alert dialog while it exists."; } } } delete params; return 0; }
HRESULT Camera::takePicture(HWND hwndOwner,LPTSTR pszFilename) { HRESULT hResult = S_OK; #if defined(_WIN32_WCE) && !defined( OS_PLATFORM_MOTCE ) SHCAMERACAPTURE shcc; StringW root; convertToStringW(rho_rhodesapp_getblobsdirpath(), root); wsprintf( pszFilename, L"%s", root.c_str() ); create_folder(pszFilename); //LPCTSTR szExt = wcsrchr(pszFilename, '.'); TCHAR filename[256]; generate_filename(filename,L".jpg"); // Set the SHCAMERACAPTURE structure. ZeroMemory(&shcc, sizeof(shcc)); shcc.cbSize = sizeof(shcc); shcc.hwndOwner = hwndOwner; shcc.pszInitialDir = pszFilename; shcc.pszDefaultFileName = filename; shcc.pszTitle = TEXT("Camera"); shcc.VideoTypes = CAMERACAPTURE_VIDEOTYPE_MESSAGING; shcc.nResolutionWidth = 176; shcc.nResolutionHeight = 144; shcc.nVideoTimeLimit = 15; shcc.Mode = CAMERACAPTURE_MODE_STILL; // Display the Camera Capture dialog. hResult = SHCameraCapture(&shcc); // The next statements will execute only after the user takes // a picture or video, or closes the Camera Capture dialog. if (S_OK == hResult) { LPTSTR fname = get_file_name(shcc.szFile,pszFilename); if (fname) { StringCchCopy(pszFilename, MAX_PATH, fname); free(fname); } else { LOG(ERROR) + "takePicture error get file: " + shcc.szFile; hResult = E_INVALIDARG; } }else { LOG(ERROR) + "takePicture failed with code: " + LOGFMT("0x%X") + hResult; } #endif //_WIN32_WCE return hResult; }
LPTSTR Camera::get_file_name(LPCTSTR from, LPCTSTR to) { int len; StringW destinationString = convertToStringW(from); size_t found; len = destinationString.find_last_of('\\'); LOG(INFO) + "Test Check: " + len; StringW name = destinationString.substr(len+1); int length1 = wcslen(name.c_str()); wchar_t* returnName = (wchar_t*) malloc(length1*sizeof(wchar_t)+1); wcscpy(returnName,name.c_str()); len = wcslen(to); if (wcsncmp( to, from, len )!=0) { StringW strPathTo = to; strPathTo += L"\\"; strPathTo += name; if ( !copy_file( from, strPathTo.c_str() ) ) return 0; } if (wcsncmp( to, from, len )!=0) { if( DeleteFile(from) != 0 ) LOG(INFO) + "File Deletion Failed " ; else LOG(INFO) + "File Deleted Successfull " ; } return returnName; }
void rho_sys_app_uninstall(const char *appname) { #ifdef OS_WINDOWS_DESKTOP CRegKey oKey; StringW strKeyPath; LONG res = openRegAppPath(appname, oKey, strKeyPath); if ( res != ERROR_SUCCESS ) { LOG(ERROR) + "Cannot open registry key: " + strKeyPath + "; Code:" + res; } else { TCHAR szBuf[MAX_PATH+1]; ULONG nChars = MAX_PATH; res = oKey.QueryStringValue(L"Uninstaller", szBuf, &nChars); if ( res != ERROR_SUCCESS ) LOG(ERROR) + "Cannot read registry key: Uninstaller; Code:" + res; else { StringW strFullPath = szBuf; rho_wmsys_run_appW( strFullPath.c_str(), L"" ); } } #else CFilePath oPath(appname); String strAppName = oPath.getFolderName(); StringW strRequest = L"<wap-provisioningdoc><characteristic type=\"UnInstall\">" L"<characteristic type=\""; strRequest += convertToStringW(strAppName) + L"\">" L"<parm name=\"uninstall\" value=\"1\"/>" L"</characteristic>" L"</characteristic></wap-provisioningdoc>"; #if defined( OS_WINCE )&& !defined( OS_PLATFORM_MOTCE ) HRESULT hr = E_FAIL; LPWSTR wszOutput = NULL; hr = DMProcessConfigXML(strRequest.c_str(), CFGFLAG_PROCESS, &wszOutput); if (FAILED(hr) || !wszOutput ) LOG(ERROR) + "DMProcessConfigXML failed: " + hr; else { } if ( wszOutput ) free( wszOutput ); #endif #endif }
void rho_sys_run_app(const char *appname, VALUE params) { CFilePath oPath(appname); String strAppName = oPath.getFolderName(); StringW strKeyPath = L"Software\\Apps\\"; strKeyPath += convertToStringW(strAppName); StringW strParamsW; if ( params && !rho_ruby_is_NIL(params) ) { convertToStringW(getStringFromValue(params), strParamsW); /* int nPos = strParamsW.find(L"rhogallery_app"); if ( nPos >= 0 ) { if ( nPos == 0 || (nPos > 0 && strParamsW.at(nPos-1)!= '-' ) ) strParamsW.insert(nPos, L"-"); } */ strParamsW.insert(0, L"-RhoStartParams:"); } CRegKey oKey; LONG res = oKey.Open(HKEY_LOCAL_MACHINE, strKeyPath.c_str(), KEY_READ); if ( res != ERROR_SUCCESS ) { LOG(ERROR) + "Cannot open registry key: " + strKeyPath + "; Code:" + res; }else { TCHAR szBuf[256]; ULONG nChars = 255; res = oKey.QueryStringValue(L"InstallDir", szBuf, &nChars ); if ( res != ERROR_SUCCESS ) LOG(ERROR) + "Cannot read registry key: InstallDir; Code:" + res; else { StringW strFullPath = szBuf; if ( strFullPath[strFullPath.length()-1] != '/' && strFullPath[strFullPath.length()-1] != '\\' ) strFullPath += L"\\"; StringW strBaseName; convertToStringW(oPath.getBaseName(), strBaseName); strFullPath += strBaseName; rho_wmsys_run_appW(strFullPath.c_str(), strParamsW.c_str()); } } }
extern "C" LRESULT rho_wmimpl_draw_splash_screen(HWND hWnd) { LOG(INFO) + "PAINT"; CSplashScreen& splash = RHODESAPP().getSplashScreen(); splash.start(); PAINTSTRUCT ps; HDC hDC = BeginPaint(hWnd, &ps); StringW pathW = convertToStringW(RHODESAPP().getLoadingPngPath()); HBITMAP hbitmap = SHLoadImageFile(pathW.c_str()); if (hbitmap) { BITMAP bmp; GetObject(hbitmap, sizeof(bmp), &bmp); RECT rcClient; GetClientRect(hWnd, &rcClient); CDC hdcMem = CreateCompatibleDC(hDC); hdcMem.FillSolidRect(&rcClient, RGB(255,255,255)); HGDIOBJ resObj = SelectObject(hdcMem, hbitmap); int nLeft = rcClient.left, nTop=rcClient.top, nWidth = bmp.bmWidth, nHeight=bmp.bmHeight, Width = rcClient.right - rcClient.left, Height = rcClient.bottom - rcClient.top; if (splash.isFlag(CSplashScreen::HCENTER) ) nLeft = (Width-nWidth)/2; if (splash.isFlag(CSplashScreen::VCENTER) ) nTop = (Height-nHeight)/2; if (splash.isFlag(CSplashScreen::VZOOM) ) nHeight = Height; if (splash.isFlag(CSplashScreen::HZOOM) ) nWidth = Width; StretchBlt(hDC, nLeft, nTop, nWidth, nHeight, hdcMem, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY); //BitBlt(hDC, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), hdcMem, 0, 0, SRCCOPY); SelectObject(hdcMem, resObj); DeleteObject(hbitmap); //DeleteObject(hdcMem); } EndPaint(hWnd, &ps); return 1; }
static unsigned int copyFolder(const StringW& strSrc, const StringW& strDst, boolean bMove) { unsigned int nErr = 0; CRhoFile::createFolder(convertToStringA(strDst).c_str()); StringW wFolderMask = CFilePath::join(strSrc, L"*"); WIN32_FIND_DATAW FindFileData = {0}; HANDLE hFind = INVALID_HANDLE_VALUE; #if defined(OS_WP8) hFind = FindFirstFileExW(wFolderMask.c_str(), FindExInfoStandard, &FindFileData, FindExSearchNameMatch, NULL, FIND_FIRST_EX_CASE_SENSITIVE); #else hFind = FindFirstFileW(wFolderMask.c_str(), &FindFileData); #endif if (hFind == INVALID_HANDLE_VALUE) return GetLastError(); do{ if (!wcscmp(FindFileData.cFileName , L".")) continue ; if (!wcscmp(FindFileData.cFileName , L"..")) continue ; if ( FindFileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY ) { int i = 0; nErr = copyFolder( CFilePath::join(strSrc,FindFileData.cFileName), CFilePath::join(strDst,FindFileData.cFileName), bMove ); } else { if ( bMove ) { CRhoFile::deleteFile(convertToStringA(CFilePath::join(strDst,FindFileData.cFileName)).c_str()); nErr = CRhoFile::renameFile(convertToStringA(CFilePath::join(strSrc,FindFileData.cFileName)).c_str(), convertToStringA(CFilePath::join(strDst,FindFileData.cFileName)).c_str()); } else nErr = CRhoFile::copyFile( convertToStringA(CFilePath::join(strSrc,FindFileData.cFileName)).c_str(), convertToStringA(CFilePath::join(strDst,FindFileData.cFileName)).c_str() ); } if ( nErr != 0 ) return nErr; }while (FindNextFileW(hFind, &FindFileData) != 0); FindClose(hFind); return 0; }
void CMainWindow::createCustomMenu() { CMenu menu; CMenu sub; CMenu popup; if (!m_pBrowserEng->GetHTMLWND()) return; VERIFY(menu.CreateMenu()); VERIFY(popup.CreatePopupMenu()); menu.AppendMenu(MF_POPUP, (UINT) popup.m_hMenu, _T("")); RHODESAPP().getAppMenu().copyMenuItems(m_arAppMenuItems); #ifdef ENABLE_DYNAMIC_RHOBUNDLE String strIndexPage = CFilePath::join(RHODESAPP().getStartUrl(),"index"RHO_ERB_EXT); if ( RHODESAPP().getCurrentUrl().compare(RHODESAPP().getStartUrl()) == 0 || RHODESAPP().getCurrentUrl().compare(strIndexPage) == 0 ) m_arAppMenuItems.addElement(CAppMenuItem("Reload RhoBundle","reload_rhobundle")); #endif //ENABLE_DYNAMIC_RHOBUNDLE //update UI with custom menu items USES_CONVERSION; for ( int i = m_arAppMenuItems.size() - 1; i >= 0; i--) { CAppMenuItem& oItem = m_arAppMenuItems.elementAt(i); if (oItem.m_eType == CAppMenuItem::emtSeparator) popup.InsertMenu(0, MF_BYPOSITION | MF_SEPARATOR, (UINT_PTR)0, (LPCTSTR)0); else { StringW strLabelW = convertToStringW(oItem.m_strLabel); popup.InsertMenu(0, MF_BYPOSITION, ID_CUSTOM_MENU_ITEM_FIRST + i, oItem.m_eType == CAppMenuItem::emtClose ? _T("Exit") : strLabelW.c_str() ); } } RECT rect; GetWindowRect(&rect); rect.bottom -= m_menuBarHeight; sub.Attach(menu.GetSubMenu(0)); sub.TrackPopupMenu( TPM_RIGHTALIGN | TPM_BOTTOMALIGN | TPM_LEFTBUTTON | TPM_VERNEGANIMATION, rect.right-1, rect.bottom-1, m_hWnd); sub.Detach(); }
void Application::_init(const StringW& appType) { _uiEngine = NULL; if (appType.startsWith(Ascii8("UI"))) { #if defined(FOG_BUILD_UI) // Create the UIEngine by name. _uiEngine = createUIEngine(appType); #else Logger::warning("Fog::Application", "_init", "Requested to create UI based application, but Fog/UI was disabled at compile-time."); #endif } EventLoopImpl* eventLoopImpl = NULL; #if defined(FOG_BUILD_UI) if (_uiEngine != NULL) eventLoopImpl = _uiEngine->_eventLoop._d->addRef(); #endif // FOG_BUILD_UI // Create EventLoop by of the required type. if (eventLoopImpl == NULL) eventLoopImpl = createEventLoop(appType); if (eventLoopImpl != NULL) _homeThread->_eventLoop.adopt(eventLoopImpl); // Set global application instance (singleton). if (_instance == NULL) _instance = this; }
void CRhodesModule::createAutoStartShortcut() { #ifdef OS_WINCE StringW strLnk = L"\\Windows\\StartUp\\"; strLnk += convertToStringW(getAppName()); strLnk += L".lnk"; StringW strAppPath = L"\""; char rootpath[MAX_PATH]; GetModuleFileNameA(NULL,rootpath,MAX_PATH); strAppPath += convertToStringW(rootpath); strAppPath += L"\" -minimized"; DWORD dwRes = SHCreateShortcut( (LPTSTR)strLnk.c_str(), (LPTSTR)strAppPath.c_str()); #endif }
STDMETHODIMP ScriptObject::GetIDsOfNames(REFIID riid, OLECHAR **rgszNames, UINT cNames, LCID lcid, DISPID *rgDispID) { //USES_CONVERSION; for (UINT n = 0; n < cNames; n++) { StringW strName = rgszNames[n]; List<SCRIPT_OBJECT_METHOD_TABLE>::Iterator iter = _methodTable.GetHeadPosition(); while (_methodTable.iteratorValid(iter)) { if (strName.Compare(iter->name) == 0) { rgDispID[n] = iter->dispid; break; } iter++; } if (!_methodTable.iteratorValid(iter)) return E_UNEXPECTED; } return S_OK; }
/* * vislib::sys::Path::Concatenate */ vislib::StringW vislib::sys::Path::Concatenate(const StringW& lhs, const StringW& rhs, const bool canonicalise) { StringW retval(lhs); if (lhs.EndsWith(SEPARATOR_W) && rhs.StartsWith(SEPARATOR_W)) { retval.Append(rhs.PeekBuffer() + 1); } else if (!lhs.EndsWith(SEPARATOR_W) && !rhs.StartsWith(SEPARATOR_W)) { retval.Append(SEPARATOR_W); retval.Append(rhs); } else { retval.Append(rhs); } return canonicalise ? Path::Canonicalise(retval) : retval; }
void DrawingContextImpl::drawText(int x, int y, int nWidth, int nHeight, String const &text, int color) { RHO_MAP_TRACE2("DrawingContext drawText with x = %d, y = %d", x, y); HFONT hfontTahoma; LOGFONT logfont; HFONT hfontSave = NULL; memset (&logfont, 0, sizeof (logfont)); logfont.lfHeight = 18; logfont.lfWidth = 0; logfont.lfEscapement = 0; logfont.lfOrientation = 0; logfont.lfWeight = FW_BOLD; logfont.lfItalic = FALSE; logfont.lfUnderline = FALSE; logfont.lfStrikeOut = FALSE; logfont.lfCharSet = DEFAULT_CHARSET; logfont.lfOutPrecision = OUT_DEFAULT_PRECIS; logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS; logfont.lfQuality = DEFAULT_QUALITY; logfont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; _tcsncpy (logfont.lfFaceName, TEXT("Tahoma"), LF_FACESIZE); logfont.lfFaceName[LF_FACESIZE-1] = TEXT('\0'); // Ensure null termination hfontTahoma = CreateFontIndirect (&logfont); if (hfontTahoma) { hfontSave = (HFONT) SelectObject(mHDC, hfontTahoma); } StringW pathW = convertToStringW(text); SetBkMode(mHDC, TRANSPARENT); SetTextColor(mHDC, color & 0xFFFFFF); //TextOut(mHDC, x, y, pathW.c_str(), pathW.length()); RECT r; r.left = x; r.top = y; r.right = x+nWidth; r.bottom = y + nHeight; DrawText(mHDC, pathW.c_str(), -1, &r, DT_LEFT | DT_TOP); if (hfontTahoma) { SelectObject(mHDC, hfontSave); DeleteObject (hfontTahoma); } }
void rho_wmsys_run_app(const char* szPath, const char* szParams ) { SHELLEXECUTEINFO se = {0}; se.cbSize = sizeof(SHELLEXECUTEINFO); se.fMask = SEE_MASK_NOCLOSEPROCESS; se.lpVerb = L"Open"; StringW strAppNameW; convertToStringW(szPath, strAppNameW); for(int i = 0; i<(int)strAppNameW.length();i++) { if ( strAppNameW.at(i) == '/' ) strAppNameW.at(i) = '\\'; } se.lpFile = strAppNameW.c_str(); StringW strParamsW; if ( szParams && *szParams ) { convertToStringW(szParams, strParamsW); se.lpParameters = strParamsW.c_str(); } ShellExecuteEx(&se); }
const char* rho_webview_execute_js(const char* js, int index) { // String strJS = "javascript:"; //strJS += js; //RAWTRACEC1("Execute JS: %s", js); //rho_webview_navigate(strJS.c_str(), index); StringW strJsW; convertToStringW(js, strJsW); TNavigateData* nd = new TNavigateData(); nd->index = index; nd->url = _tcsdup(strJsW.c_str()); ::PostMessage( getMainWnd(), WM_COMMAND, IDM_EXECUTEJS, (LPARAM)nd ); return ""; }
LRESULT CMainWindow::OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) { PAINTSTRUCT ps; HDC hDC = BeginPaint(&ps); CSplashScreen& splash = RHODESAPP().getSplashScreen(); splash.start(); StringW pathW = convertToStringW(RHODESAPP().getLoadingPngPath()); HBITMAP hbitmap = SHLoadImageFile(pathW.c_str()); if (!hbitmap) return 0; BITMAP bmp; GetObject(hbitmap, sizeof(bmp), &bmp); HDC hdcMem = CreateCompatibleDC(hDC); HGDIOBJ resObj = SelectObject(hdcMem, hbitmap); CRect rcClient; GetClientRect(&rcClient); int nLeft = rcClient.left, nTop=rcClient.top, nWidth = bmp.bmWidth, nHeight=bmp.bmHeight; if (splash.isFlag(CSplashScreen::HCENTER) ) nLeft = (rcClient.Width()-nWidth)/2; if (splash.isFlag(CSplashScreen::VCENTER) ) nTop = (rcClient.Height()-nHeight)/2; if (splash.isFlag(CSplashScreen::VZOOM) ) nHeight = rcClient.Height(); if (splash.isFlag(CSplashScreen::HZOOM) ) nWidth = rcClient.Width(); StretchBlt(hDC, nLeft, nTop, nWidth, nHeight, hdcMem, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY); //BitBlt(hDC, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), hdcMem, 0, 0, SRCCOPY); SelectObject(hdcMem, resObj); DeleteObject(hbitmap); DeleteObject(hdcMem); EndPaint(&ps); bHandled = TRUE; return 0; }
LRESULT CMainWindow::OnExecuteJS(WORD /*wNotifyCode*/, WORD /*wID*/, HWND hWndCtl, BOOL& /*bHandled*/) { TNavigateData* nd = (TNavigateData*)hWndCtl; if (nd) { LPTSTR wcurl = (LPTSTR)(nd->url); if (wcurl) { StringW strUrlW; if(_memicmp(wcurl,L"JavaScript:",11*2) != 0) strUrlW = L"javascript:"; strUrlW += wcurl; Navigate2((LPWSTR)strUrlW.c_str(), nd->index); } delete nd; } return 0; }
/* * vislib::sys::Path::GetUserHomeDirectoryW */ vislib::StringW vislib::sys::Path::GetUserHomeDirectoryW(void) { #ifdef _WIN32 StringW retval; if (FAILED(::SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL, 0, retval.AllocateBuffer(MAX_PATH)))) { throw SystemException(ERROR_NOT_FOUND, __FILE__, __LINE__); } if (!retval.EndsWith(SEPARATOR_W)) { retval += SEPARATOR_W; } return retval; #else /* _WIN32 */ return StringW(GetUserHomeDirectoryA()); #endif /* _WIN32 */ }
static DWORD WINAPI playThreadProc(LPVOID lpParam) { DWORD dwRet = S_OK; CMediaplayerSingleton *pMediaplayer = (CMediaplayerSingleton *)lpParam; if (pMediaplayer) { LOG(INFO) + __FUNCTION__ + "pMediaplayer object exists: using lFilename: " + lFilename.c_str(); if (!PlaySound(lFilename.c_str(), NULL, SND_FILENAME|SND_SYNC|SND_NODEFAULT)) { LOG(INFO) + __FUNCTION__ + " PlaySound function failed, API supports only wav extention "; dwRet = false; } CloseHandle(pMediaplayer->m_hPlayThread); pMediaplayer->m_hPlayThread = NULL; } return dwRet; }
void CMainWindow::ShowLoadingPage() { String fname = RHODESAPP().getLoadingPagePath(); size_t pos = fname.find("file://"); if (pos == 0 && pos != std::string::npos) fname.erase(0, 7); CRhoFile oFile; StringW strTextW; if ( oFile.open( fname.c_str(), common::CRhoFile::OpenReadOnly) ) oFile.readStringW(strTextW); else { LOG(ERROR) + "failed to open loading page \"" + fname + "\""; strTextW = L"<html><head><title>Loading...</title></head><body><h1>Loading...</h1></body></html>"; } m_pBrowserEng->NavigateToHtml(strTextW.c_str()); }
BSTR loadLoadingHtml() { rho::String fname = RHODESAPP().getLoadingPagePath(); size_t pos = fname.find("file://"); if (pos == 0 && pos != std::string::npos) fname.erase(0, 7); CRhoFile oFile; StringW strTextW; if ( oFile.open( fname.c_str(), common::CRhoFile::OpenReadOnly) ) oFile.readStringW(strTextW); else { LOG(ERROR) + "failed to open loading page \"" + fname + "\""; strTextW = L"<html><head><title>Loading...</title></head><body><h1>Loading...</h1></body></html>"; } return SysAllocString(strTextW.c_str()); }
// Object name can contain characters [A-Z], [a-z], '-', '_', [0-9]. Numbers // are not allowed for the first character. static err_t Object_validatePropertyName(const StringW& name) { const CharW* data = name.getData(); size_t length = name.getLength(); if (length == 0) return ERR_PROPERTY_INVALID; CharW c = data[0]; if (!(c.isAsciiLetter() || c == CharW('_') || c == CharW('-'))) return ERR_PROPERTY_INVALID; for (size_t i = 1; i < length; i++) { if (!(c.isAsciiNumlet() || c == CharW('_') || c == CharW('-'))) return ERR_PROPERTY_INVALID; } return ERR_OK; }
static LONG openRegAppPath(const char *appname, CRegKey& oKey, StringW& strKeyPath) { CFilePath oPath(appname); String strAppName = oPath.getFolderName(); #ifdef OS_WINDOWS_DESKTOP strKeyPath = L"SOFTWARE\\"; #else strKeyPath = L"Software\\Apps\\"; #endif strKeyPath += convertToStringW(strAppName); String_replace(strKeyPath, '/', '\\' ); #ifdef OS_WINDOWS_DESKTOP return oKey.Open(HKEY_CURRENT_USER, strKeyPath.c_str(), KEY_READ|KEY_WOW64_64KEY ); #else return oKey.Open(HKEY_LOCAL_MACHINE, strKeyPath.c_str(), KEY_READ ); #endif }
/*static*/ unsigned int CRhoFile::deleteFolder(const char* szFolderPath) { #if defined(WINDOWS_PLATFORM) && !defined(OS_WP8) StringW swPath; convertToStringW(szFolderPath, swPath); wchar_t* name = new wchar_t[ swPath.length() + 2]; swprintf(name, L"%s%c", swPath.c_str(), '\0'); translate_wchar(name, L'/', L'\\'); SHFILEOPSTRUCTW fop = {0}; fop.hwnd = NULL; fop.wFunc = FO_DELETE; fop.pFrom = name; fop.pTo = NULL; fop.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR #if defined(OS_WINDOWS_DESKTOP) || defined(OS_PLATFORM_MOTCE) | FOF_NOERRORUI #endif ; int result = SHFileOperationW(&fop); delete name; return result == 0 ? 0 : (unsigned int)-1; #elif defined(OS_WP8) StringW swPath; convertToStringW(szFolderPath, swPath); recursiveDeleteDirectory(swPath); return 0; #elif defined (OS_ANDROID) RemoveFileFunctor funct(szFolderPath); return funct(""); #else rho_file_impl_delete_folder(szFolderPath); return 0; #endif }
bool CAppManager::RemoveFolder(String pathname) { if (pathname.length() > 0) { StringW swPath = convertToStringW(pathname); TCHAR name[MAX_PATH+2]; wsprintf(name, L"%s%c", swPath.c_str(), '\0'); SHFILEOPSTRUCT fop; fop.hwnd = NULL; fop.wFunc = FO_DELETE; fop.pFrom = name; fop.pTo = NULL; fop.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_NOCONFIRMMKDIR; int result = SHFileOperation(&fop); return result == 0; } return false; }
int rho_sys_is_app_installed(const char *appname) { #ifdef OS_WINDOWS_DESKTOP CRegKey oKey; StringW strKeyPath; LONG res = openRegAppPath(appname, oKey, strKeyPath); return res == ERROR_SUCCESS ? 1 : 0; #else int nRet = 0; CFilePath oPath(appname); String strAppName = oPath.getFolderName(); StringW strRequest = L"<wap-provisioningdoc><characteristic type=\"UnInstall\">" L"<characteristic-query type=\""; strRequest += convertToStringW(strAppName) + L"\"/>" L"</characteristic></wap-provisioningdoc>"; #if defined( OS_WINCE ) && !defined( OS_PLATFORM_MOTCE ) HRESULT hr = E_FAIL; LPWSTR wszOutput = NULL; hr = DMProcessConfigXML(strRequest.c_str(), CFGFLAG_PROCESS, &wszOutput); if (FAILED(hr) || !wszOutput ) LOG(ERROR) + "DMProcessConfigXML failed: " + hr; else { StringW strResp = L"<characteristic type=\""; strResp += convertToStringW(strAppName) + L"\">"; nRet = wcsstr(wszOutput, strResp.c_str()) != 0 ? 1 : 0; } if ( wszOutput ) free( wszOutput ); #endif return nRet; #endif }
const char* rho_webview_execute_js(const char* js, int index) { // String strJS = "javascript:"; //strJS += js; //RAWTRACEC1("Execute JS: %s", js); //rho_webview_navigate(strJS.c_str(), index); StringW strJsW; convertToStringW(js, strJsW); #ifdef RHODES_EMULATOR TNavigateData* nd = (TNavigateData*)malloc(sizeof(TNavigateData)); nd->index = index; nd->url = _tcsdup(strJsW.c_str()); ::PostMessage( getMainWnd(), WM_COMMAND, IDM_EXECUTEJS, (LPARAM)nd ); #else ::PostMessage( getMainWnd(), WM_COMMAND, IDM_EXECUTEJS, (LPARAM)_tcsdup(strJsW.c_str()) ); #endif return ""; }
/* * vislib::sys::Path::PurgeDirectory */ void vislib::sys::Path::PurgeDirectory(const StringW& path, bool recursive) { StringW fullpath = Resolve(path); if (!fullpath.EndsWith(SEPARATOR_W)) fullpath += SEPARATOR_W; DirectoryIteratorW iter(fullpath); while (iter.HasNext()) { DirectoryEntryW entry = iter.Next(); if (entry.Type == DirectoryEntryW::FILE) { vislib::sys::File::Delete(fullpath + entry.Path); } else if (entry.Type == DirectoryEntryW::DIRECTORY) { if (recursive) { DeleteDirectory(fullpath + entry.Path, true); } } else { ASSERT(false); // DirectoryEntry is something unknown to this // implementation. Check DirectoryIterator for // changes. } } }
void rho_sys_app_install(const char *url) { #ifdef OS_WINDOWS_DESKTOP String sUrl = url; CFilePath oFile(sUrl); String filename = RHODESAPP().getRhoUserPath()+ oFile.getBaseName(); if (CRhoFile::isFileExist(filename.c_str()) && (CRhoFile::deleteFile(filename.c_str()) != 0)) { LOG(ERROR) + "rho_sys_app_install() file delete failed: " + filename; } else { NetRequest NetRequest; NetResponse resp = getNetRequest(&NetRequest).pullFile(sUrl, filename, NULL, NULL); if (resp.isOK()) { StringW filenameW = convertToStringW(filename); LOG(INFO) + "Downloaded " + sUrl + " to " + filename; rho_wmsys_run_appW(filenameW.c_str(), L""); } else { LOG(ERROR) + "rho_sys_app_install() download failed: " + sUrl; } } #else rho_sys_open_url(url); #endif }
void CMainWindow::createCustomMenu() { HMENU hMenu = (HMENU)m_menuBar.SendMessage(SHCMBM_GETSUBMENU, 0, IDM_SK2_MENU); //except exit item int num = GetMenuItemCount (hMenu); for (int i = 0; i < (num - 1); i++) DeleteMenu(hMenu, 0, MF_BYPOSITION); RHODESAPP().getAppMenu().copyMenuItems(m_arAppMenuItems); //update UI with cusom menu items USES_CONVERSION; for ( int i = m_arAppMenuItems.size() - 1; i >= 0; i--) { CAppMenuItem& oItem = m_arAppMenuItems.elementAt(i); StringW strLabelW = convertToStringW(oItem.m_strLabel); if (oItem.m_eType == CAppMenuItem::emtSeparator) InsertMenu(hMenu, 0, MF_BYPOSITION | MF_SEPARATOR, 0, 0); else if (oItem.m_eType != CAppMenuItem::emtExit && oItem.m_eType != CAppMenuItem::emtClose) InsertMenu(hMenu, 0, MF_BYPOSITION, ID_CUSTOM_MENU_ITEM_FIRST + i, strLabelW.c_str() ); } }