summaryrefslogtreecommitdiffstats
path: root/src/windows/leash/Lglobals.cpp
diff options
context:
space:
mode:
authorSam Hartman <hartmans@mit.edu>2011-09-28 21:02:14 +0000
committerSam Hartman <hartmans@mit.edu>2011-09-28 21:02:14 +0000
commitcaef99b21536d9e8c2f9c637fcf020b4e082db5d (patch)
treeb360ec8449876ea170691685cde758d9849fc8ef /src/windows/leash/Lglobals.cpp
parent8481c14298a1886f63bec0d7cdfd800a86b4c127 (diff)
downloadkrb5-caef99b21536d9e8c2f9c637fcf020b4e082db5d.tar.gz
krb5-caef99b21536d9e8c2f9c637fcf020b4e082db5d.tar.xz
krb5-caef99b21536d9e8c2f9c637fcf020b4e082db5d.zip
Initial import of KFW 3.2.2 Leash32 code
Signed-off-by: Alexey Melnikov <aamelnikov@gmail.com> git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@25278 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/windows/leash/Lglobals.cpp')
-rw-r--r--src/windows/leash/Lglobals.cpp148
1 files changed, 148 insertions, 0 deletions
diff --git a/src/windows/leash/Lglobals.cpp b/src/windows/leash/Lglobals.cpp
new file mode 100644
index 000000000..861255e6c
--- /dev/null
+++ b/src/windows/leash/Lglobals.cpp
@@ -0,0 +1,148 @@
+//*****************************************************************************
+// File: lgobals.cpp
+// By: Arthur David Leather
+// Created: 12/02/98
+// Copyright: @1998 Massachusetts Institute of Technology - All rights
+// reserved.
+// Description: CPP file for lgobals.cpp. Contains global variables and helper
+// functions
+//
+// History:
+//
+// MM/DD/YY Inits Description of Change
+// 02/02/98 ADL Original
+//*****************************************************************************
+
+#include "stdafx.h"
+#include "leash.h"
+#include <direct.h>
+#include "lglobals.h"
+
+static const char *const conf_yes[] = {
+ "y", "yes", "true", "t", "1", "on",
+ 0,
+};
+
+static const char *const conf_no[] = {
+ "n", "no", "false", "nil", "0", "off",
+ 0,
+};
+
+int
+config_boolean_to_int(const char *s)
+{
+ const char *const *p;
+
+ for(p=conf_yes; *p; p++) {
+ if (!strcasecmp(*p,s))
+ return 1;
+ }
+
+ for(p=conf_no; *p; p++) {
+ if (!strcasecmp(*p,s))
+ return 0;
+ }
+
+ /* Default to "no" */
+ return 0;
+}
+
+
+// Global Function for deleting or putting a value in the Registry
+BOOL SetRegistryVariable(const CString& regVariable,
+ const CString& regValue,
+ const char* regSubKey)
+{
+ // Set Register Variable
+ HKEY hKey = NULL;
+ LONG err = 0L;
+
+
+ if (ERROR_SUCCESS != (err = RegOpenKeyEx(HKEY_CURRENT_USER,
+ regSubKey,
+ 0, KEY_ALL_ACCESS, &hKey)))
+ {
+ if ((err = RegCreateKeyEx(HKEY_CURRENT_USER, regSubKey, 0, 0, 0,
+ KEY_ALL_ACCESS, 0, &hKey, 0)))
+ {
+ // Error
+ return TRUE;
+ }
+ }
+
+ if (ERROR_SUCCESS == err && hKey)
+ {
+ if (regValue.IsEmpty())
+ {
+ // Delete
+ RegDeleteValue(hKey, regVariable);
+ }
+ else
+ {
+ // Insure that Name (Variable) is in the Registry and set
+ // it's new value
+ char nVariable[MAX_PATH+1];
+ char* pVARIABLE = nVariable;
+ strncpy(pVARIABLE, regValue, MAX_PATH);
+
+ if (ERROR_SUCCESS !=
+ RegSetValueEx(hKey, regVariable, 0,
+ REG_SZ, (const unsigned char*)pVARIABLE,
+ lstrlen(regValue)))
+ {
+ // Error
+ return FALSE;
+ }
+ }
+
+ RegCloseKey(hKey);
+
+ // Send this message to all top-level windows in the system
+ ::PostMessage(HWND_BROADCAST, WM_WININICHANGE, 0L, (LPARAM) regSubKey);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+VOID LeashErrorBox(LPCSTR errorMsg, LPCSTR insertedString, LPCSTR errorFlag)
+{
+ CString strMessage;
+ strMessage = errorMsg;
+ strMessage += ": ";
+ strMessage += insertedString;
+
+ MessageBox(CLeashApp::m_hProgram, strMessage, errorFlag, MB_OK);
+
+ //if (*errorFlag == 'E')
+ //ASSERT(0); // on error condition only
+}
+
+Directory::Directory(LPCSTR pathToValidate)
+{
+ m_pathToValidate = pathToValidate;
+ _getdcwd(_getdrive(), m_savCurPath, sizeof(m_savCurPath));
+}
+
+Directory::~Directory()
+{
+ if (-1 == _chdir(m_savCurPath))
+ ASSERT(0);
+}
+
+BOOL Directory::IsValidDirectory()
+{
+ if (-1 == _chdir(m_pathToValidate))
+ return FALSE;
+
+ return TRUE;
+}
+
+BOOL Directory::IsValidFile()
+{
+ CFileFind fileFind;
+ if (!fileFind.FindFile(m_pathToValidate))
+ return FALSE;
+
+ return TRUE;
+}