int CIniFile::Split( const CStr &source, LPCTSTR sep, CStrArray &dest, BOOL trim /* = TRUE */ ) { int pos = source.Find( sep ); int startPos = 0; CStr elem; int sepLen = wcslen( sep ); dest.RemoveAll(); while( pos != -1 ) { elem = source.Mid( startPos, pos-startPos ); if ( trim ) { elem.TrimLeft(); elem.TrimRight(); } dest.Add( elem ); startPos = pos+sepLen; pos = source.Find( sep, startPos ); } elem = source.Mid( startPos ); if ( trim ) { elem.TrimLeft(); elem.TrimRight(); } dest.Add( elem ); return dest.GetSize(); }
void CDlgInput::OnSize(UINT nType, int cx, int cy) { CDialog::OnSize(nType, cx, cy); if ( GetDlgItem(IDC_LABEL) == NULL || ! ::IsWindow( GetDlgItem(IDC_LABEL)->m_hWnd ) ) return; CRect pos; int infoBottom; GetDlgItem( IDC_LABEL )->GetWindowRect( &pos ); ScreenToClient( pos ); if ( m_Label.IsEmpty() ) { GetDlgItem( IDC_LABEL )->ShowWindow( SW_HIDE ); infoBottom = 0; } else { HDC dc = ::GetWindowDC( GetDlgItem(IDC_LABEL)->m_hWnd ); CStrArray lines; if ( m_Label.IsEmpty() ) { lines.Add( L"" ); GetDlgItem( IDC_LABEL )->SetWindowText(L""); } else { SplitLines( dc, (LPCTSTR)m_Label, lines, pos.Width() ); CString infoWrapped; for ( int i=0; i<lines.GetSize(); i++ ) { infoWrapped += lines[i]; if ( i<lines.GetSize()-1 ) infoWrapped += "\n"; } GetDlgItem( IDC_LABEL )->SetWindowText(infoWrapped); //UpdateData(FALSE); } SIZE size; GetTextExtentPoint( dc, L"W", 1, &size ); pos.top = 4; pos.left = 4; pos.right = cx - 8; infoBottom = pos.bottom = pos.top + size.cy * lines.GetSize(); ::ReleaseDC( GetDlgItem(IDC_LABEL)->m_hWnd, dc ); GetDlgItem( IDC_LABEL )->MoveWindow( pos ); GetDlgItem( IDC_LABEL )->Invalidate(); } //GetDlgItem(IDC_LABEL)->GetWindowRect( &pos ); //ScreenToClient( &pos ); //GetDlgItem(IDC_LABEL)->MoveWindow( &pos ); if ( Multiline ) { int height; GetDlgItem(IDOK)->GetWindowRect( &pos ); ScreenToClient( &pos ); height = pos.bottom-pos.top; pos.top = cy - height - 4; pos.bottom = cy - 4; pos.left = 4; pos.right = cx/2 - 4; GetDlgItem(IDOK)->MoveWindow( &pos ); GetDlgItem(IDCANCEL)->GetWindowRect( &pos ); ScreenToClient( &pos ); pos.top = cy - height - 4; pos.bottom = cy - 4; pos.left = cx/2 + 4; pos.right = cx - 8; GetDlgItem(IDCANCEL)->MoveWindow( &pos ); GetDlgItem(IDC_EDIT)->GetWindowRect( &pos ); ScreenToClient( &pos ); pos.top = infoBottom + 4; pos.bottom = cy - height - 8; pos.left = 4; pos.right = cx - 8; GetDlgItem(IDC_EDIT)->MoveWindow( &pos ); } else { int height; GetDlgItem(IDC_EDIT)->GetWindowRect( &pos ); ScreenToClient( &pos ); height = pos.Height(); pos.top = infoBottom + 4; pos.bottom = pos.top + height; pos.left = 4; pos.right = cx - 8; GetDlgItem(IDC_EDIT)->MoveWindow( &pos ); infoBottom = pos.bottom; ((CEdit*)GetDlgItem(IDC_EDIT))->ModifyStyle( ES_MULTILINE|ES_WANTRETURN|WS_VSCROLL, 0 ); #ifndef DESKTOP OSVERSIONINFO ver; GetVersionEx( &ver ); if ( ver.dwMajorVersion < 5 ) { #endif GetDlgItem(IDOK)->GetWindowRect( &pos ); ScreenToClient( &pos ); height = pos.bottom-pos.top; pos.top = infoBottom + 4; pos.bottom = pos.top + height; pos.left = 4; pos.right = cx/2 - 4; GetDlgItem(IDOK)->MoveWindow( &pos ); GetDlgItem(IDCANCEL)->GetWindowRect( &pos ); ScreenToClient( &pos ); pos.top = infoBottom + 4; pos.bottom = pos.top + height; pos.left = cx/2 + 4; pos.right = cx - 8; GetDlgItem(IDCANCEL)->MoveWindow( &pos ); #ifndef DESKTOP } else { GetDlgItem( IDOK )->ShowWindow( SW_HIDE ); GetDlgItem( IDCANCEL )->ShowWindow( SW_HIDE ); } #endif //((CEdit*)GetDlgItem(IDC_EDIT))->ModifyStyleEx( 0, ES_MULTILINE|ES_WANTRETURN|WS_VSCROLL ); #ifdef DESKTOP CRect client; GetWindowRect( &pos ); GetClientRect( &client ); if ( infoBottom + height + 8 != client.Height() ) { pos.bottom = pos.top + pos.Height() - client.Height() + infoBottom + height + 8; MoveWindow( &pos ); } #endif } ((CEdit*)GetDlgItem(IDC_EDIT))->SetSel(0,0,FALSE); }
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; }