time_t getFileAccessed(const std::string& filename){ FILETIME accesstime; HANDLE hFile = CreateFileA(filename.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if(hFile != INVALID_HANDLE_VALUE){GetFileTime(hFile,NULL,&accesstime,NULL);} else{return 0;} CloseHandle(hFile); return SystemTimeToUnixTime(accesstime); }
LRESULT CTimePickerDialog::OnOK(WORD /*wNotifyCode*/, WORD wID, HWND hwnd, BOOL& /*bHandled*/) { SYSTEMTIME sysTime; DateTime_GetSystemtime (GetDlgItem(IDC_TIME_CTRL), &sysTime); m_returnTime = SystemTimeToUnixTime (&sysTime); EndDialog(wID); return 0; }
bool touchmind::util::TimeUtil::SystemTimeToJavaTime(SYSTEMTIME systemTime, LONGLONG* javaTime) { time_t t; if (!SystemTimeToUnixTime(systemTime, &t)) { return false; } UnixTimeToJavaTime(t, systemTime.wMilliseconds, javaTime); return true; }
LRESULT CDateTimePickerDialog::OnOK(WORD /*wNotifyCode*/, WORD wID, HWND hwnd, BOOL& /*bHandled*/) { SYSTEMTIME sysTime; if (m_format == CDateTimeMessage::FORMAT_TIME) { DateTime_GetSystemtime (GetDlgItem(IDC_TIME_CTRL), &sysTime); } else if (m_format == CDateTimeMessage::FORMAT_DATE) { DateTime_GetSystemtime (GetDlgItem(IDC_DATE_CTRL), &sysTime); } else if (m_format == CDateTimeMessage::FORMAT_DATE_TIME) { SYSTEMTIME time, date; DateTime_GetSystemtime (GetDlgItem(IDC_TIME_CTRL), &time); DateTime_GetSystemtime (GetDlgItem(IDC_DATE_CTRL), &date); sysTime.wYear = date.wYear; sysTime.wMonth = date.wMonth; sysTime.wDayOfWeek = date.wDayOfWeek; sysTime.wDay = date.wDay; sysTime.wHour = time.wHour; sysTime.wMinute = time.wMinute; sysTime.wSecond = time.wSecond; } else { LOG(ERROR) + "invalid format"; m_returnTime = 0; } m_returnTime = SystemTimeToUnixTime (&sysTime); EndDialog(wID); return 0; }
BOOL CMortScriptApp::InitInstance() { SetRegistryKey( L"Mort" ); CParseCmdLine myCmdLine; myCmdLine.ParseCmdLine( m_lpCmdLine ); TCHAR exe[MAX_PATH]; ::GetModuleFileName(NULL,exe,MAX_PATH); ExecuteFileName = exe; CStr file = myCmdLine.Filename; // m_lpCmdLine; // file.TrimLeft( '\"' ); file.TrimRight( '\"' ); if ( myCmdLine.RegOnly || file.IsEmpty() ) { RegisterFileClass(); RegisterFileType( L".jscr", L"JScripts" ); RegisterFileType( L".mscr", L"JScripts" ); if ( !myCmdLine.RegOnly ) { MessageBox( NULL , L".jscr and .mscr extensions registered.\nPlease run any .jscr/.mscr file or read the manual.\n\n" L"(c) Mirko Schenk 2005-2007" , L"JScripts V" + CStr( VERSION_INFO ) , MB_OK|MB_SETFOREGROUND ); } } else { if ( file.GetLength() >= 4 /* file.GetLength() >= 8 && file.Right(8).CompareNoCase( L".mortrun" ) == 0 || file.GetLength() >= 5 && file.Right(5).CompareNoCase( L".mscr" ) == 0 */ ) { CStr mutexName = file; mutexName.MakeLower(); #ifdef DESKTOP // Windows XP doesn't like some path characters in the mutex' name mutexName.Replace( ':', '_' ); mutexName.Replace( '\\', '/' ); #endif MutexName = (LPCTSTR)mutexName; HANDLE mutex = ::CreateMutex(NULL, FALSE, MutexName); if ( mutex!=NULL ) { int exists = ::GetLastError(); if ( exists == ERROR_ALREADY_EXISTS) { DWORD procId = GetRunningScriptProcId( file ); if ( procId != NULL ) { /* CString msg; msg.Format( L"Process ID: %08x", procId ); MessageBox( NULL, msg, L"Debug", MB_SETFOREGROUND ); */ FindAppT findApp; findApp.procId = procId; findApp.hWnd = NULL; ::EnumWindows( FindApplicationWindowProc, (LPARAM)&findApp ); if ( findApp.hWnd != NULL ) { // msg.Format( L"Set foreground window: %08x", findApp.hWnd ); // MessageBox( NULL, msg, L"Debug", MB_SETFOREGROUND ); ::SetForegroundWindow( findApp.hWnd ); } } else exists = 0; //MessageBox( NULL, L"Process opened", L"Debug", MB_SETFOREGROUND ); /* TCHAR procName[256]; ::GetModuleFileName((HMODULE)procId,procName,256); //MessageBox( NULL, procName, L"Debug", MB_SETFOREGROUND ); if ( CString(procName).Right(14).CompareNoCase( L"MortScript.exe" ) == 0 ) { int aw = MessageBox( NULL , L"Script seems to be running. Cancel old script?" , L"Script already running" , MB_YESNO|MB_SETFOREGROUND ); if ( aw == IDYES ) { RegWriteDW( HKEY_CURRENT_USER, L"Software\\JScripts\\Abort", MutexName, 1 ); DWORD exitCode = 0; SetCursor(LoadStandardCursor(IDC_WAIT)); for ( int i=0; i<=10; i++ ) { Sleep(1000); if ( GetExitCodeProcess( hProc, &exitCode ) == FALSE ) { //MessageBox( NULL, L"GetExitCode failed", L"Debug", MB_SETFOREGROUND ); exitCode = 0; break; } else { if ( exitCode != STILL_ACTIVE ) { //MessageBox( NULL, L"No longer active", L"Debug", MB_SETFOREGROUND ); break; } } } SetCursor(LoadStandardCursor(IDC_ARROW)); if ( exitCode == STILL_ACTIVE ) { int aw = MessageBox( NULL , L"Script seems to be hanging or busy. Terminate old script?" , L"Script still running" , MB_YESNO|MB_SETFOREGROUND ); if ( aw == IDYES ) { TerminateProcess( hProc, 0 ); } } } } else { exists = 0; } CloseHandle( hProc ); } else { exists = 0; } */ } if ( exists != ERROR_ALREADY_EXISTS ) { HKEY key; if ( RegOpenKeyEx( HKEY_CURRENT_USER, L"Software\\JScripts\\Processes", 0, 0, &key ) == ERROR_SUCCESS ) { RegDeleteValue( key, MutexName ); RegCloseKey( key ); } DWORD currProcId = GetCurrentProcessId(); //CString dbg; //dbg.Format(L"ProcId: %d", GetCurrentProcessId()); //MessageBox( NULL, dbg, L"Debug", MB_SETFOREGROUND ); // Remove old script entries with same process id if ( RegOpenKeyEx( HKEY_CURRENT_USER, L"Software\\JScripts\\Processes", 0, 0, &key ) == ERROR_SUCCESS ) { int idx; TCHAR valName[MAX_PATH]; DWORD valSize = MAX_PATH, type; DWORD value, valueSize = sizeof(DWORD); CStrArray oldProcesses; for ( idx = 0; RegEnumValue( key, idx, valName, &valSize, NULL, &type, (BYTE*)&value, &valueSize ) == ERROR_SUCCESS; idx++ ) { if ( type == REG_DWORD && value == currProcId ) { oldProcesses.Add( valName ); } valSize = MAX_PATH; valueSize = sizeof(DWORD); } for ( idx = 0; idx < oldProcesses.GetSize(); idx++ ) { RegDeleteValue( key, oldProcesses.GetAt(idx) ); } RegCloseKey( key ); } RegWriteDW( HKEY_CURRENT_USER, L"Software\\JScripts\\Processes", MutexName, currProcId ); if ( myCmdLine.WaitForFile > 0 && (long)FileOrDirExists( file, 0 ) == 0 ) { CDlgWait wait(NULL); wait.AllowOK = TRUE; wait.Countdown = myCmdLine.WaitForFile; wait.Expression = L"FileExists(\"" + file + L"\")"; wait.Title = L"JScripts"; wait.m_Label = L"Script " + file + " not found, waiting for existance (storage card not initialized?)"; wait.DoModal(); } if ( myCmdLine.WaitForFile <= 0 || (long)FileOrDirExists( file, 0 ) == 1 ) { g_hInst = theApp.m_hInstance; SYSTEMTIME now; GetLocalTime( &now ); long seed = SystemTimeToUnixTime( now ); srand( seed ); AppPath = m_pszHelpFilePath; AppPath = AppPath.Left( AppPath.ReverseFind('\\') ); ScriptAborted = CreateEvent( 0, TRUE, FALSE, CStr(MutexName)+L"ScriptAborted" ); StatusDialog = new CDlgStatus( file ); //status.DoModal(); CInterpreter interpreter; //Debug(file); //jwz:modi interpreter.RunFile( file ); interpreter.Parser(); //jwz:modi end if ( StatusWindow != NULL ) { StatusDialog->ScriptFinished = TRUE; SendMessage( StatusWindow, WM_EXIT_STATUS, 0, 0 ); WaitForSingleObject( StatusDialogFinished, INFINITE ); CloseHandle( StatusDialogFinished ); } delete StatusDialog; UnloadToolhelp(); CloseHandle( ScriptAborted ); ReleaseMutex( mutex ); Variables.RemoveAll(); for ( int i = 0; i<LocalVariablesStack.GetSize(); i++ ) delete (CMapStrToValue*)LocalVariablesStack.GetAt(i); POSITION pos = FileHandles.GetStartPosition(); CStr key; void *value; while ( pos != 0 ) { FileHandles.GetNextAssoc( pos, key, value ); if ( value != NULL ) { delete (CFileInfo*)value; } } FileHandles.RemoveAll(); if ( ChoiceFont != NULL ) DeleteObject( ChoiceFont ); if ( StatusListFont != NULL ) DeleteObject( StatusListFont ); } if ( RegOpenKeyEx( HKEY_CURRENT_USER, L"Software\\JScripts\\Processes", 0, KEY_WRITE, &key ) == ERROR_SUCCESS ) { RegDeleteValue( key, MutexName ); RegCloseKey( key ); } } CloseHandle( mutex ); } else { int error = ::GetLastError(); MessageBox( NULL , L"Error creating mutex" , L"JScripts" , MB_OK|MB_SETFOREGROUND ); } } else { MessageBox( NULL , L"Invalid file type for MortScript" , L"JScripts" , MB_OK|MB_SETFOREGROUND ); } } // Since the dialog has been closed, return FALSE so that we exit the // application, rather than start the application's message pump. return FALSE; }