[Sphere-axis-commits] CVS: Axis AdditionalSettingsDlg.cpp,1.2,1.3 AdditionalSettingsDlg.h,1.2,1.3 CS
Brought to you by:
pesterle
From: Philip E. <pes...@us...> - 2002-05-20 19:32:34
|
Update of /cvsroot/sphere-axis/Axis In directory usw-pr-cvs1:/tmp/cvs-serv27483 Modified Files: AdditionalSettingsDlg.cpp AdditionalSettingsDlg.h CScriptObjects.cpp Drewsky.cpp Drewsky.dsp Drewsky.h remoteconnection.cpp remoteconnection.h Log Message: code changes to support selective file loading Index: AdditionalSettingsDlg.cpp =================================================================== RCS file: /cvsroot/sphere-axis/Axis/AdditionalSettingsDlg.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** AdditionalSettingsDlg.cpp 14 May 2002 20:03:34 -0000 1.2 --- AdditionalSettingsDlg.cpp 20 May 2002 19:14:42 -0000 1.3 *************** *** 32,35 **** --- 32,44 ---- m_bAllowMultiple = FALSE; //}}AFX_DATA_INIT + + m_hFolderIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_FOLDER)); + m_hDocIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_DOC)); + + m_ilIcons.Create(16, 16, ILC_MASK, 0, 1); + m_iFolderIndex = m_ilIcons.Add(m_hFolderIcon); + m_iDocIndex = m_ilIcons.Add(m_hDocIcon); + + m_iCurProfileSel = -1; } *************** *** 67,70 **** --- 76,85 ---- BEGIN_MESSAGE_MAP(CAdditionalSettingsDlg, CDialog) //{{AFX_MSG_MAP(CAdditionalSettingsDlg) + ON_LBN_SELCHANGE(IDC_AS_PROFILES, OnSelchangeAsProfiles) + ON_BN_CLICKED(IDC_AS_NEWPROFILE, OnAsNewprofile) + ON_BN_CLICKED(IDC_AS_EDITPROFILE, OnAsEditprofile) + ON_BN_CLICKED(IDC_AS_DELETEPROFILE, OnAsDeleteprofile) + ON_BN_CLICKED(IDC_AS_MULBROWSE, OnAsMulbrowse) + ON_BN_CLICKED(IDC_AS_CLIENTBROWSE, OnAsClientbrowse) //}}AFX_MSG_MAP END_MESSAGE_MAP() *************** *** 144,148 **** CString csProfile; csProfile.Format("Local: %s", szBuffer); ! this->m_clbProfiles.AddString(szBuffer); } iIndex++; --- 159,163 ---- CString csProfile; csProfile.Format("Local: %s", szBuffer); ! this->m_clbProfiles.AddString(csProfile); } iIndex++; *************** *** 165,169 **** CString csProfile; csProfile.Format("Remote: %s", szBuffer); ! this->m_clbProfiles.AddString(szBuffer); } iIndex++; --- 180,184 ---- CString csProfile; csProfile.Format("Remote: %s", szBuffer); ! this->m_clbProfiles.AddString(csProfile); } iIndex++; *************** *** 173,176 **** --- 188,403 ---- UpdateData(FALSE); + + m_ctcScripts.SetImageList(&m_ilIcons, TVSIL_NORMAL); + return TRUE; + } + + void CAdditionalSettingsDlg::OnSelchangeAsProfiles() + { + int iSel = this->m_clbProfiles.GetCurSel(); + if ( m_iCurProfileSel != -1 && m_iCurProfileSel != iSel ) + UpdateProfile(); + m_iCurProfileSel = iSel; + if ( iSel == -1 ) + { + this->m_cbDeleteProfile.EnableWindow(FALSE); + this->m_cbEditProfile.EnableWindow(FALSE); + this->m_ctcScripts.DeleteAllItems(); + return; + } + this->m_cbDeleteProfile.EnableWindow(TRUE); + this->m_cbEditProfile.EnableWindow(TRUE); + m_ctcScripts.DeleteAllItems(); + + // Populate the tree control with the scripts available to this profile + CString csProfile; + m_clbProfiles.GetText(iSel, csProfile); + if (csProfile.Find("Local:") == 0 ) + { + // Local profile + // Find the root directory of this profile + CString csKey = _T("SOFTWARE\\Menasoft\\GM Tools\\Local Profiles\\") + _T(csProfile.Mid(7)); + CString csRoot = Main->GetRegistryString("Root Directory", "", HKEY_LOCAL_MACHINE, csKey); + CStringArray csaSelectedScripts; + Main->GetRegistryMultiSz("Selected Scripts", &csaSelectedScripts, HKEY_LOCAL_MACHINE, csKey); + // Make a node in the tree control for this directory + HTREEITEM hRoot = m_ctcScripts.InsertItem(csRoot); + ParseDirectory(LPCTSTR(csRoot), hRoot, &csaSelectedScripts); + } + else + { + // Remote profile + CString csKey = _T("SOFTWARE\\Menasoft\\GM Tools\\Remote Profiles\\") + _T(csProfile.Mid(8)); + CRemoteConnection remote(csProfile.Mid(8)); + CStringArray csaSelectedScripts; + Main->GetRegistryMultiSz("Selected Scripts", &csaSelectedScripts, HKEY_LOCAL_MACHINE, csKey); + HTREEITEM hRoot = m_ctcScripts.InsertItem(""); + ParseRemoteDirectory("." , hRoot, &csaSelectedScripts, &remote); + } + } + + void CAdditionalSettingsDlg::OnAsNewprofile() + { + + } + + void CAdditionalSettingsDlg::OnAsEditprofile() + { + + } + + void CAdditionalSettingsDlg::OnAsDeleteprofile() + { + + } + + void CAdditionalSettingsDlg::OnAsMulbrowse() + { + + } + + void CAdditionalSettingsDlg::OnAsClientbrowse() + { + + } + + void CAdditionalSettingsDlg::ParseDirectory(LPCTSTR pszPath, HTREEITEM hNode, CStringArray *pSelections) + { + WIN32_FIND_DATA findData; + memset(&findData, 0x00, sizeof(findData)); + CString csTestFile; + csTestFile.Format("%s\\*", pszPath); + HANDLE hSearch = FindFirstFile(csTestFile, &findData); + if ( hSearch != INVALID_HANDLE_VALUE ) + { + BOOL bStatus = TRUE; + while (bStatus) + { + if ( findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) + { + // Recurse this + if ( strcmp(findData.cFileName, "..") == 0 || strcmp(findData.cFileName, ".") == 0 ) + { + // Ignore this one + } + else + { + HTREEITEM hBranch = m_ctcScripts.InsertItem(findData.cFileName, m_iFolderIndex, m_iFolderIndex, hNode); + CString csNewPath; + csNewPath.Format("%s\\%s", pszPath, findData.cFileName); + ParseDirectory(csNewPath, hBranch, pSelections); + } + } + else + { + CString csFileName = _T(findData.cFileName); + if ( csFileName.Right(4).CompareNoCase(".scp") == 0) + { + CString csFullPath; + csFullPath.Format("%s\\%s", pszPath, findData.cFileName); + HTREEITEM hNewItem = m_ctcScripts.InsertItem(findData.cFileName, m_iDocIndex, m_iDocIndex, hNode); + if ( IsSelected(pSelections, csFullPath ) ) + m_ctcScripts.SetCheck(hNewItem); + + } + } + bStatus = FindNextFile(hSearch, &findData); + } + FindClose(hSearch); + } + } + + void CAdditionalSettingsDlg::ParseRemoteDirectory(LPCTSTR pszPath, HTREEITEM hNode, CStringArray * pSelections, CRemoteConnection * pRemote) + { + CStringArray csaFiles, csaDirectories; + pRemote->GetDirectory(pszPath, &csaFiles, &csaDirectories); + int i; + for ( i = 0; i <= csaDirectories.GetUpperBound(); i++ ) + { + if ( csaDirectories.GetAt(i) == "." || csaDirectories.GetAt(i) == ".." ) + continue; + HTREEITEM hBranch = m_ctcScripts.InsertItem(csaDirectories.GetAt(i), m_iFolderIndex, m_iFolderIndex, hNode); + CString csNewPath; + csNewPath.Format("%s\\%s", pszPath, csaDirectories.GetAt(i)); + if ( csNewPath.Find(".\\") == 0 ) + csNewPath = csNewPath.Mid(2); + ParseRemoteDirectory(csNewPath, hBranch, pSelections, pRemote); + } + for ( i = 0; i <= csaFiles.GetUpperBound(); i++ ) + { + if ( csaFiles.GetAt(i).Right(4).CompareNoCase(".scp") == 0 ) + { + CString csFullPath; + csFullPath.Format("%s\\%s", pszPath, csaFiles.GetAt(i)); + if ( csFullPath.Find(".\\") == 0 ) + csFullPath = csFullPath.Mid(2); + HTREEITEM hNewItem = m_ctcScripts.InsertItem(csaFiles.GetAt(i), m_iDocIndex, m_iDocIndex, hNode); + if ( IsSelected(pSelections, csFullPath) ) + m_ctcScripts.SetCheck(hNewItem); + } + } + } + + void CAdditionalSettingsDlg::UpdateProfile() + { + if ( m_iCurProfileSel == -1 ) + return; + CString csProfile; + this->m_clbProfiles.GetText(m_iCurProfileSel, csProfile); + CStringArray aSelectedScripts; + HTREEITEM hRoot = m_ctcScripts.GetRootItem(); + CString csRootDir = m_ctcScripts.GetItemText(hRoot); + GetSelections(hRoot, csRootDir, &aSelectedScripts); + + CString csProfileKey; + if (csProfile.Find("Local:") == 0 ) + { + // Local profile + csProfileKey = _T("SOFTWARE\\Menasoft\\GM Tools\\Local Profiles\\") + _T(csProfile.Mid(7)); + } + else + { + // Remote profile + csProfileKey = _T("SOFTWARE\\Menasoft\\GM Tools\\Remote Profiles\\") + _T(csProfile.Mid(8)); + } + Main->PutRegistryMultiSz("Selected Scripts", &aSelectedScripts, HKEY_LOCAL_MACHINE, csProfileKey); + } + + void CAdditionalSettingsDlg::GetSelections(HTREEITEM hNode, CString csRootDir, CStringArray *pSelections) + { + HTREEITEM hChild = m_ctcScripts.GetNextItem(hNode, TVGN_CHILD); + while (hChild != NULL ) + { + CString csPath; + if ( csRootDir != "" ) + csPath = csRootDir + _T("\\") + m_ctcScripts.GetItemText(hChild); + else + csPath = m_ctcScripts.GetItemText(hChild); + if ( m_ctcScripts.ItemHasChildren(hChild) ) + GetSelections(hChild, csPath, pSelections); + else + { + // This is a script file + if ( m_ctcScripts.GetCheck(hChild) ) + pSelections->Add(csPath); + } + hChild = m_ctcScripts.GetNextItem(hChild, TVGN_NEXT); + } + } + + bool CAdditionalSettingsDlg::IsSelected(CStringArray * pSelections, CString csFile) + { + for ( int i = 0; i <= pSelections->GetUpperBound(); i++ ) + { + if ( csFile == pSelections->GetAt(i) ) + return true; + } + return false; + } + + void CAdditionalSettingsDlg::OnOK() + { + UpdateProfile(); + CDialog::OnOK(); } Index: AdditionalSettingsDlg.h =================================================================== RCS file: /cvsroot/sphere-axis/Axis/AdditionalSettingsDlg.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** AdditionalSettingsDlg.h 14 May 2002 20:03:34 -0000 1.2 --- AdditionalSettingsDlg.h 20 May 2002 19:14:42 -0000 1.3 *************** *** 8,11 **** --- 8,13 ---- // + #include "RemoteConnection.h" + ///////////////////////////////////////////////////////////////////////////// // CAdditionalSettingsDlg dialog *************** *** 54,61 **** --- 56,81 ---- // Implementation protected: + int m_iCurProfileSel; + CImageList m_ilIcons; + int m_iFolderIndex; + int m_iDocIndex; + HICON m_hDocIcon; + HICON m_hFolderIcon; + void ParseDirectory(LPCTSTR pszPath, HTREEITEM hNode, CStringArray * pSelections); + void ParseRemoteDirectory(LPCTSTR pszPath, HTREEITEM hNode, CStringArray * pSelections, CRemoteConnection * pRemote); + bool IsSelected(CStringArray * pSelections, CString csFile); + void UpdateProfile(); + void GetSelections(HTREEITEM hNode, CString csRootDir, CStringArray * pSelections); // Generated message map functions //{{AFX_MSG(CAdditionalSettingsDlg) virtual BOOL OnInitDialog(); + afx_msg void OnSelchangeAsProfiles(); + afx_msg void OnAsNewprofile(); + afx_msg void OnAsEditprofile(); + afx_msg void OnAsDeleteprofile(); + afx_msg void OnAsMulbrowse(); + afx_msg void OnAsClientbrowse(); + virtual void OnOK(); //}}AFX_MSG DECLARE_MESSAGE_MAP() Index: CScriptObjects.cpp =================================================================== RCS file: /cvsroot/sphere-axis/Axis/CScriptObjects.cpp,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -r1.17 -r1.18 *** CScriptObjects.cpp 16 May 2002 01:31:57 -0000 1.17 --- CScriptObjects.cpp 20 May 2002 19:14:42 -0000 1.18 *************** *** 2466,2469 **** --- 2466,2470 ---- e->Delete(); } + m_pDlg->SetPos(csfInput.GetLength()); csfInput.Close(); DestroyProgressDialog(); *************** *** 2492,2495 **** --- 2493,2520 ---- if ( Main->GetProfileType() == PROFILE_REMOTE ) { + CStringArray csaScripts; + CString csKey = _T("SOFTWARE\\Menasoft\\GM Tools\\Remote Profiles\\") + Main->GetProfileString(); + Main->GetRegistryMultiSz("Selected Scripts", &csaScripts, HKEY_LOCAL_MACHINE, csKey); + if ( csaScripts.GetSize() > 0 ) + { + // Load the specified scripts + this->m_bNewFormat = true; + m_pRemote->SetDialog(m_pDlg); + for ( int i = 0; i <= csaScripts.GetUpperBound(); i++ ) + { + m_pRemote->UpdateFile(csaScripts.GetAt(i)); + CString csLocalFile; + csLocalFile.Format("%s\\%s", Main->GetProfileString(), csaScripts.GetAt(i)); + LoadFile(csLocalFile); + } + // Categorize everything + CategorizeLocations(); + CategorizeItems(); + CategorizeNPCs(); + this->m_bDeleteDialog = true; + DestroyProgressDialog(); + // We're done + return; + } #ifdef _AXIS m_pRemote->SetDialog(m_pDlg); *************** *** 2501,2504 **** --- 2526,2549 ---- else { + // Local profile + // Has the user selected particular scripts to load? + CStringArray csaScripts; + CString csKey = _T("SOFTWARE\\Menasoft\\GM Tools\\Local Profiles\\") + Main->GetProfileString(); + Main->GetRegistryMultiSz("Selected Scripts", &csaScripts, HKEY_LOCAL_MACHINE, csKey); + if ( csaScripts.GetSize() > 0 ) + { + // Load the specified scripts + this->m_bNewFormat = true; + for ( int i = 0; i <= csaScripts.GetUpperBound(); i++ ) + LoadFile(csaScripts.GetAt(i)); + // Categorize everything + CategorizeLocations(); + CategorizeItems(); + CategorizeNPCs(); + this->m_bDeleteDialog = true; + DestroyProgressDialog(); + // We're done + return; + } // Load the INI file first Main->m_log.Add("Reading server INI file from working directory"); Index: Drewsky.cpp =================================================================== RCS file: /cvsroot/sphere-axis/Axis/Drewsky.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -r1.13 -r1.14 *** Drewsky.cpp 15 May 2002 22:18:48 -0000 1.13 --- Drewsky.cpp 20 May 2002 19:14:43 -0000 1.14 *************** *** 567,569 **** --- 567,654 ---- } return PROFILE_UNDEFINED; + } + + void CDrewskyApp::PutRegistryMultiSz(CString csValue, CStringArray * pStrings, HKEY hMainKey, CString csSubKey) + { + HKEY hKey; + DWORD dwDisp; + LONG lStatus = RegCreateKeyEx(hMainKey, csSubKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisp); + + // Find out how much space we need to allocate for the string buffer + int i = 0; + int iLength = 0; + for ( i = 0; i <= pStrings->GetUpperBound(); i++ ) + iLength += ( pStrings->GetAt(i).GetLength() + 1); + + char * pszStrings = new char [iLength + 1]; + + memset(pszStrings, 0x00, iLength + 1); + char * ptr = pszStrings; + for ( i = 0; i <= pStrings->GetUpperBound(); i++ ) + { + memcpy(ptr, LPCTSTR(pStrings->GetAt(i)), pStrings->GetAt(i).GetLength()); + ptr += pStrings->GetAt(i).GetLength() + 1; + } + + if ( lStatus != ERROR_SUCCESS ) + { + m_log.Add("Unable to open registry key %s for writing. Last error was %s", csSubKey, strerror(lStatus) ); + return; + } + lStatus = RegSetValueEx(hKey, csValue, 0, REG_MULTI_SZ, ((BYTE *) pszStrings), iLength ); + if ( lStatus != ERROR_SUCCESS ) + m_log.Add("Error writing value %s to the registry. Last error was %s", csValue, strerror(lStatus) ); + RegCloseKey(hKey); + + delete [] pszStrings; + } + + void CDrewskyApp::GetRegistryMultiSz(CString csValue, CStringArray * pStrings, HKEY hMainKey, CString csSubKey) + { + // Make sure the input array is empty + pStrings->RemoveAll(); + + HKEY hKey; + if ( RegOpenKeyEx(hMainKey, csSubKey, 0, KEY_READ, &hKey) != ERROR_SUCCESS ) + return; + DWORD dwType, dwSize; + // Need to find out how big the buffer is + dwSize = 0; + LONG lStatus = RegQueryValueEx(hKey, LPCTSTR(csValue), 0, &dwType, NULL, &dwSize); + + if ( dwSize == 0 ) + { + RegCloseKey(hKey); + return; + } + + char * pszBuffer = new char [dwSize]; + memset(pszBuffer, 0x00, dwSize); + lStatus = RegQueryValueEx(hKey, LPCTSTR(csValue), 0, &dwType, (BYTE*) pszBuffer, &dwSize); + char * pDataPtr = pszBuffer; + + if ( lStatus != ERROR_SUCCESS ) + { + if ( lStatus == ERROR_FILE_NOT_FOUND ) + m_log.Add("Unable to find value %s in the registry.", csValue); + else + m_log.Add("Error reading value %s from registry. Last error was %s", csValue, strerror(GetLastError()) ); + } + else + { + // parse the registry value + DWORD dwOffset = 0; + while ( dwOffset < dwSize ) + { + CString csValue = _T(pDataPtr); + pStrings->Add(csValue); + pDataPtr += csValue.GetLength() + 1; + dwOffset += csValue.GetLength() + 1; + } + + } + if ( dwType != REG_MULTI_SZ ) + m_log.Add("Registry value of wrong type for %s. Type was %ld, expected %ld", csValue, dwType, REG_MULTI_SZ); + RegCloseKey(hKey); + delete [] pszBuffer; } Index: Drewsky.dsp =================================================================== RCS file: /cvsroot/sphere-axis/Axis/Drewsky.dsp,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -r1.24 -r1.25 *** Drewsky.dsp 12 May 2002 18:58:18 -0000 1.24 --- Drewsky.dsp 20 May 2002 19:14:43 -0000 1.25 *************** *** 9,18 **** !MESSAGE use the Export Makefile command and run !MESSAGE ! !MESSAGE NMAKE /f "drewsky.mak". !MESSAGE !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: !MESSAGE ! !MESSAGE NMAKE /f "drewsky.mak" CFG="drewsky - Win32 Future Debug" !MESSAGE !MESSAGE Possible choices for configuration are: --- 9,18 ---- !MESSAGE use the Export Makefile command and run !MESSAGE ! !MESSAGE NMAKE /f "Drewsky.mak". !MESSAGE !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: !MESSAGE ! !MESSAGE NMAKE /f "Drewsky.mak" CFG="drewsky - Win32 Future Debug" !MESSAGE !MESSAGE Possible choices for configuration are: *************** *** 977,980 **** --- 977,985 ---- # End Target # End Project + # Section drewsky : {2B360722-F116-4004-A71A-5E14B4C4873E} + # 2:5:Class:CUOMap + # 2:10:HeaderFile:uomap.h + # 2:8:ImplFile:uomap.cpp + # End Section # Section drewsky : {EF8782A5-4E77-4990-A8C7-0E28C52E90CF} # 2:5:Class:CUOArt *************** *** 982,996 **** # 2:8:ImplFile:uoart.cpp # End Section - # Section drewsky : {2AC21540-4C63-4663-BF24-D1DBD9205223} - # 2:21:DefaultSinkHeaderFile:uomap.h - # 2:16:DefaultSinkClass:CUOMap - # End Section # Section drewsky : {0904F7B3-2339-44C9-857C-6EB6CFEFA3B6} # 2:21:DefaultSinkHeaderFile:uoart.h # 2:16:DefaultSinkClass:CUOArt # End Section ! # Section drewsky : {2B360722-F116-4004-A71A-5E14B4C4873E} ! # 2:5:Class:CUOMap ! # 2:10:HeaderFile:uomap.h ! # 2:8:ImplFile:uomap.cpp # End Section --- 987,996 ---- # 2:8:ImplFile:uoart.cpp # End Section # Section drewsky : {0904F7B3-2339-44C9-857C-6EB6CFEFA3B6} # 2:21:DefaultSinkHeaderFile:uoart.h # 2:16:DefaultSinkClass:CUOArt # End Section ! # Section drewsky : {2AC21540-4C63-4663-BF24-D1DBD9205223} ! # 2:21:DefaultSinkHeaderFile:uomap.h ! # 2:16:DefaultSinkClass:CUOMap # End Section Index: Drewsky.h =================================================================== RCS file: /cvsroot/sphere-axis/Axis/Drewsky.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -r1.10 -r1.11 *** Drewsky.h 15 May 2002 22:18:48 -0000 1.10 --- Drewsky.h 20 May 2002 19:14:43 -0000 1.11 *************** *** 72,75 **** --- 72,77 ---- CString GetRegistryString(CString csValue, CString csDefault = _T(""), HKEY hMainKey = HKEY_LOCAL_MACHINE, CString csSubKey = "Software\\Menasoft\\GM Tools"); DWORD GetRegistryDword(CString csValue, DWORD dwDefault = 0, HKEY hMainKey = HKEY_LOCAL_MACHINE, CString csSubKey = "Software\\Menasoft\\GM Tools"); + void PutRegistryMultiSz(CString csValue, CStringArray * pStrings, HKEY hMainKey = HKEY_LOCAL_MACHINE, CString csSubKey = "SOFTWARE\\Menasoft\\GM Tools"); + void GetRegistryMultiSz(CString csValue, CStringArray * pStrings, HKEY hMainKey = HKEY_LOCAL_MACHINE, CString csSubKey = "SOFTWARE\\Menasoft\\GM Tools"); void SetDialogColors(); CScriptObjects * m_pScripts; Index: remoteconnection.cpp =================================================================== RCS file: /cvsroot/sphere-axis/Axis/remoteconnection.cpp,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -r1.19 -r1.20 *** remoteconnection.cpp 14 May 2002 20:03:34 -0000 1.19 --- remoteconnection.cpp 20 May 2002 19:14:43 -0000 1.20 *************** *** 75,108 **** CRemoteConnection::CRemoteConnection() { ! int iPort = atoi(Main->m_csAxissvrPort); ! if (iPort == 0) ! iPort = 4006; ! Main->m_log.Add("Connecting to remote server on IP %s, port %ld", Main->m_csServerIP, iPort); ! m_bDeleteWindow = false; ! m_pDlg = NULL; ! if ( m_pDlg == NULL ) ! { ! m_bDeleteWindow = true; ! m_pDlg = new CFileReadProgress; ! m_pDlg->Create(IDD_FILEREAD_PROGRESS); ! } ! if ( m_pDlg ) ! m_pDlg->m_csMessage.SetWindowText("Connecting to remote server..."); ! m_sock.m_hSocket = socket(AF_INET, SOCK_STREAM, 0); ! setsockopt(m_sock.m_hSocket, SOL_SOCKET, SO_DONTLINGER, "1", 1); ! if ( m_sock.Connect(Main->m_csServerIP, iPort) ) ! m_bIsValid = true; ! else ! m_bIsValid = false; ! // For some reason, if we don't wait here, we'll likely kill hogsvr with a broken pipe. ! if ( m_bIsValid ) ! m_bIsValid = this->Logon(); ! else ! { ! CString csMessage; ! Main->m_log.Add("Unable to connect to axis server running on IP %s, port %ld", Main->m_csServerIP, iPort); ! csMessage.Format("Unable to connect to axissvr running on IP %s, port %ld.", Main->m_csServerIP, iPort ); ! AfxMessageBox(csMessage, MB_OK | MB_ICONSTOP ); ! } } --- 75,87 ---- CRemoteConnection::CRemoteConnection() { ! // Use default profile ! ReadProfile(Main->GetProfileString()); ! Initialize(); ! } ! ! CRemoteConnection::CRemoteConnection(CString csProfile) ! { ! ReadProfile(csProfile); ! Initialize(); } *************** *** 128,132 **** return false; } ! Send(Main->m_csUserID, strlen(Main->m_csUserID)); ZeroMemory(szBuffer, sizeof(szBuffer)); rc = Receive(szBuffer, sizeof(szBuffer)); --- 107,111 ---- return false; } ! Send(m_csUsername, strlen(m_csUsername)); ZeroMemory(szBuffer, sizeof(szBuffer)); rc = Receive(szBuffer, sizeof(szBuffer)); *************** *** 136,140 **** return false; } ! Send(Main->m_csPassword, strlen(Main->m_csPassword)); ZeroMemory(szBuffer, sizeof(szBuffer)); rc = Receive(szBuffer, sizeof(szBuffer)); --- 115,119 ---- return false; } ! Send(m_csPassword, strlen(m_csPassword)); ZeroMemory(szBuffer, sizeof(szBuffer)); rc = Receive(szBuffer, sizeof(szBuffer)); *************** *** 540,544 **** // Didn't get the entire file....delete the temporary file Main->m_log.Add("EOF message never received from remote server for file %s", csRemoteFileName); ! CFile::Remove(csLocalFile); } if ( m_pDlg ) --- 519,530 ---- // Didn't get the entire file....delete the temporary file Main->m_log.Add("EOF message never received from remote server for file %s", csRemoteFileName); ! try ! { ! CFile::Remove(csLocalFile); ! } ! catch (CFileException * e) ! { ! e->Delete(); ! } } if ( m_pDlg ) *************** *** 846,850 **** return rc; } ! if ( i++ > Main->m_iReceiveTimeout ) { Main->m_log.Add("Timeout exceeded while receiving incoming packet."); --- 832,836 ---- return rc; } ! if ( i++ > m_iReceiveTimeout ) { Main->m_log.Add("Timeout exceeded while receiving incoming packet."); *************** *** 883,887 **** return nRead; } ! if ( i++ > Main->m_iReceiveTimeout ) { Main->m_log.Add("Timeout exceeded while receiving data from remote server."); --- 869,873 ---- return nRead; } ! if ( i++ > m_iReceiveTimeout ) { Main->m_log.Add("Timeout exceeded while receiving data from remote server."); *************** *** 1231,1233 **** m_bDeleteWindow = false; m_pDlg = pDlg; ! } \ No newline at end of file --- 1217,1298 ---- m_bDeleteWindow = false; m_pDlg = pDlg; ! } ! ! void CRemoteConnection::Initialize() ! { ! Main->m_log.Add("Connecting to remote server on IP %s, port %ld", m_csIP, m_iRemotePort); ! m_bDeleteWindow = false; ! m_pDlg = NULL; ! if ( m_pDlg == NULL ) ! { ! m_bDeleteWindow = true; ! m_pDlg = new CFileReadProgress; ! m_pDlg->Create(IDD_FILEREAD_PROGRESS); ! } ! if ( m_pDlg ) ! m_pDlg->m_csMessage.SetWindowText("Connecting to remote server..."); ! m_sock.m_hSocket = socket(AF_INET, SOCK_STREAM, 0); ! setsockopt(m_sock.m_hSocket, SOL_SOCKET, SO_DONTLINGER, "1", 1); ! if ( m_sock.Connect(m_csIP, m_iRemotePort) ) ! m_bIsValid = true; ! else ! m_bIsValid = false; ! // For some reason, if we don't wait here, we'll likely kill hogsvr with a broken pipe. ! if ( m_bIsValid ) ! m_bIsValid = this->Logon(); ! else ! { ! CString csMessage; ! Main->m_log.Add("Unable to connect to axis server running on IP %s, port %ld", m_csIP, m_iRemotePort); ! csMessage.Format("Unable to connect to axissvr running on IP %s, port %ld.", m_csIP, m_iRemotePort ); ! AfxMessageBox(csMessage, MB_OK | MB_ICONSTOP ); ! } ! } ! ! void CRemoteConnection::ReadProfile(CString csProfile) ! { ! CString csKey = _T("SOFTWARE\\Menasoft\\GM Tools\\Remote Profiles\\") + csProfile; ! m_iRemotePort = atoi(Main->GetRegistryString("HogPort", "4006", HKEY_LOCAL_MACHINE, csKey)); ! m_csIP = Main->GetRegistryString("ServerIP", "", HKEY_LOCAL_MACHINE, csKey); ! m_csPassword = Encrypt(Main->GetRegistryString("Password", "", HKEY_LOCAL_MACHINE, csKey)); ! m_csUsername = Main->GetRegistryString("Username", "", HKEY_LOCAL_MACHINE, csKey); ! m_iReceiveTimeout = Main->GetRegistryDword("ReceiveTimeout", 60000, HKEY_LOCAL_MACHINE, csKey); ! } ! ! void CRemoteConnection::UpdateFile(CString csRemoteName) ! { ! if ( !m_bIsValid ) ! return; ! CString csFile; ! if ( csRemoteName.GetAt(0) == '\\' || csRemoteName.GetAt(0) == '/' ) ! csFile = csRemoteName.Mid(1); ! else ! csFile = csRemoteName; ! csFile.Replace('/', '\\'); ! csFile.Replace(':', '!'); ! // Is this a directory? ! if ( csFile.ReverseFind('\\') == csFile.GetLength() - 1) ! return; ! else ! { ! CString csLocalFile; ! csLocalFile.Format("%s\\%s", Main->GetProfileString(), csFile); ! char szCmd[MAX_PATH]; ! sprintf(szCmd, "GFCS%s", csRemoteName); ! Send(szCmd, strlen(szCmd)); ! char szBuffer[MAX_PATH]; ! memset(&szBuffer[0], 0x00, sizeof(szBuffer)); ! Receive(&szBuffer[0], sizeof(szBuffer)); ! int iChk = atoi(szBuffer); ! CString csMessage; ! csMessage.Format("Checking for an updated version of %s", csRemoteName); ! if ( m_pDlg ) ! m_pDlg->m_csMessage.SetWindowText(csMessage); ! int iTest = GetChecksum(csLocalFile); ! if ( iChk != iTest ) ! { ! Main->m_log.Add("Checksum for file %s did not match...local = %ld, remote = %ld", csLocalFile, iTest, iChk); ! GetCustomFile(csRemoteName, csLocalFile); ! } ! } ! } Index: remoteconnection.h =================================================================== RCS file: /cvsroot/sphere-axis/Axis/remoteconnection.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -r1.3 -r1.4 *** remoteconnection.h 1 May 2002 03:33:11 -0000 1.3 --- remoteconnection.h 20 May 2002 19:14:43 -0000 1.4 *************** *** 37,44 **** --- 37,46 ---- { public: + void UpdateFile(CString csRemoteName); void StartTUS(); BYTE m_protocolLevel; bool SendCustomFile(CString csFileName, CString csTmpFile, CSObject * pObject = NULL ); CRemoteConnection(); + CRemoteConnection(CString csProfile); virtual ~CRemoteConnection(); bool IsValid() {return m_bIsValid;}; *************** *** 59,62 **** --- 61,72 ---- CFileReadProgress * m_pDlg; bool m_bDeleteWindow; + void ReadProfile(CString csProfile); + void Initialize(); + + int m_iRemotePort; + CString m_csPassword; + int m_iReceiveTimeout; + CString m_csIP; + CString m_csUsername; }; |