Пример #1
0
void CSoundUtils::RegisterTGitSounds()
{
	// create the event labels
	CRegString eventlabelerr = CRegString(_T("AppEvents\\EventLabels\\TGit_Error\\"));
	eventlabelerr = CString(MAKEINTRESOURCE(IDS_ERR_ERROR));
	CRegString eventlabelwarn = CRegString(_T("AppEvents\\EventLabels\\TGit_Warning\\"));
	eventlabelwarn = CString(MAKEINTRESOURCE(IDS_WARN_WARNING));
	CRegString eventlabelnote = CRegString(_T("AppEvents\\EventLabels\\TGit_Notification\\"));
	eventlabelnote = CString(MAKEINTRESOURCE(IDS_WARN_NOTE));

	CRegString appscheme = CRegString(_T("AppEvents\\Schemes\\Apps\\TortoiseGitProc\\"));
	appscheme = _T("TortoiseGit");

	CString apppath = CPathUtils::GetAppDirectory();

	CRegistryKey schemenamekey = CRegistryKey(_T("AppEvents\\Schemes\\Names"));
	CStringList schemenames;
	schemenamekey.getSubKeys(schemenames);
	// if the sound scheme has been modified but not save under a different name,
	// the name of the sound scheme is ".current" and not under the names list.
	// so add the .current scheme to the list too
	schemenames.AddHead(_T(".current"));
	POSITION pos;
	for (pos = schemenames.GetHeadPosition(); pos != NULL;)
	{
		CString name = schemenames.GetNext(pos);
		if ((name.CompareNoCase(_T(".none"))!=0)&&(name.CompareNoCase(_T(".nosound"))!=0))
		{
			CString errorkey = _T("AppEvents\\Schemes\\Apps\\TortoiseGitProc\\TGit_Error\\") + name + _T("\\");
			CRegString errorkeyval = CRegString(errorkey);
			if (((CString)(errorkeyval)).IsEmpty())
			{
				errorkeyval = apppath + _T("TortoiseGit_Error.wav");
			}
			CString warnkey = _T("AppEvents\\Schemes\\Apps\\TortoiseGitProc\\TGit_Warning\\") + name + _T("\\");
			CRegString warnkeyval = CRegString(warnkey);
			if (((CString)(warnkeyval)).IsEmpty())
			{
				warnkeyval = apppath + _T("TortoiseGit_Warning.wav");
			}
			CString notificationkey = _T("AppEvents\\Schemes\\Apps\\TortoiseGitProc\\TGit_Notification\\") + name + _T("\\");
			CRegString notificationkeyval = CRegString(notificationkey);
			if (((CString)(notificationkeyval)).IsEmpty())
			{
				notificationkeyval = apppath + _T("TortoiseGit_Notification.wav");
			}
		}
	}
}
Пример #2
0
LONG CRegistryKey::OpenSubkey(REGSAM samDesired, const TCHAR *pszSubkeyName, CRegistryKey &rKey)
{
  HKEY hKey;
  LONG nError = OpenSubkey(samDesired, pszSubkeyName, hKey);

  if (nError == ERROR_SUCCESS)
  {
    const TCHAR *pszKeyName = GetKeyName();
    size_t size = _tcslen(pszKeyName) + _tcslen(pszSubkeyName) + 1;
    TCHAR *pszSubkeyFullName = new (std::nothrow) TCHAR [size];
    if (!pszSubkeyFullName)
    {
      nError = RegCloseKey(hKey);
      ASSERT(nError == ERROR_SUCCESS);
      return ERROR_OUTOFMEMORY;
    }
    _tcscpy(pszSubkeyFullName,pszKeyName);
    _tcscat(pszSubkeyFullName,pszSubkeyName);
    HRESULT hr = rKey.Init(hKey,GetKeyName(),pszSubkeyName,samDesired);
    delete[] pszSubkeyName;
    if (FAILED(hr))
    {
      nError = RegCloseKey(hKey);
      ASSERT(nError == ERROR_SUCCESS);
      if (hr == (HRESULT)E_OUTOFMEMORY)
        return ERROR_OUTOFMEMORY;
      else
        return ERROR_INTERNAL_ERROR;
    }
  }

  return nError;
}
Пример #3
0
void CColumnDefMap::SaveSettings()
{
   // Write column positions to registry
   // ColumnDefMap must have non-blank name and one (1) or more entries.
   // If no name or no entries then skip it.

   if (!GetName().IsEmpty() && this->getSize() > 0)
   {
      CAppRegistryKey appKey;
      CRegistryKey settings = appKey.createSubKey("Settings");

      if (settings.isOpen())
      {
         CRegistryKey registryKey = settings.createSubKey( GetName() );  // Grid Name

         if (registryKey.isOpen())
         {
            for (int i = 0; i < this->getSize(); i++)
            {
               CColumnDef *cd = this->getAt(i);
               CString title = cd->GetTitle();     // Column Name
               int *ptr = cd->GetColIndexPtr();
               int value = *ptr;

               if (registryKey.setValue(title, value))
               {
                  // okay
               }
               // else we silently suffer
            }
         }
      }
   }
}
Пример #4
0
int main()
{
   try 
   {
      //CRegistryKey key = CRegistryKey(HKEY_LOCAL_MACHINE, _T("SOFTWARE"));
      CRegistryKey key = CRegistryKey(HKEY_LOCAL_MACHINE, _T("HARDWARE\\DESCRIPTION"));

      for (CRegistryKey::SubkeyIterator it = key.BeginSubkeyIteration();
           it != key.EndSubkeyIteration();
           ++it)
      {
         std::cout << it.GetName() << std::endl;

         CRegistryKey thisKey = it.OpenKey();

         for (CRegistryKey::ValueIterator val = thisKey.BeginValueIteration();
              val != thisKey.EndValueIteration();
              ++val)
         {
            std::cout << "   " << val.GetName() << " - " << val.AsString() << std::endl;
         }
      }

		CRegistryKey(HKEY_LOCAL_MACHINE, _T("SOFTWARE")).CreateKey(_T("JetByteTest")).SetValue(_T(""), _T("This is a Test"));

		CRegistryKey(HKEY_LOCAL_MACHINE, _T("SOFTWARE")).DeleteKey(_T("JetByteTest"));
   }
   catch (CRegistryKey::Exception &e)
   {
      e.MessageBox();
   }

   return 1;
}
int CDefaultDlg::ShowPreloaderOptionsDlg() {
	COptionsDlg dlg(this);	// Set the options dialog's parent
	CString szLPath;		// This is where autofind will save the path it finds
	CRegistryKey *softKey = this->p_cReg.KeyCurrentUser()->CreateKey(_T("SOFTWARE\\6XGate Incorporated\\PalemoonPreload"));

	// Initialize the dialog
	dlg.m_szPath = this->p_szPalemoonPath;			// Current Palemoon Path
	dlg.m_bAutoFindFF = this->p_bAutoFindFF;		// Do we AutoFind Palemoon?
	dlg.m_bWarnOnUnload = this->p_bWarnOnUnloads;	// Do we warn the user about unloading Palemoon?
	
	// Show the dialog
	int nResponse = dlg.DoModal();
	if (nResponse == IDOK) {
		// If the user enables AutoFind, try to find Palemoon automaticly
		if (dlg.m_bAutoFindFF && ::GetLatestPalemoonInstallDir(&szLPath)) {

			// Remove the saved path since AutoFind found Palemoon's path
			softKey->DeleteValue(_T("Path"));
			this->p_bAutoFindFF = TRUE;
			this->p_szPalemoonPath = szLPath;
			softKey->SetIntegerValue(_T("AutoFind"), TRUE);
			::OutputDebugString(_T("Using AutoFind Path\r\n"));

		// If the user manually entered the path that was validated, use it
		} else {

			// Disable AutoFind and get the manually entered path
			this->p_bAutoFindFF = FALSE;
			this->p_szPalemoonPath = dlg.m_szPath;

			// Trim the \ off the path if it is present save the settings
			if (this->p_szPalemoonPath[this->p_szPalemoonPath.GetLength() - 1] == _T('\\')) this->p_szPalemoonPath.TrimRight(_T('\\'));
			softKey->SetStringValue(_T("Path"), this->p_szPalemoonPath);
			softKey->SetIntegerValue(_T("AutoFind"), FALSE);
			::OutputDebugString(_T("Using Manually Entered Path\r\n"));
		
		}

		// Get and save the warning settings
		this->p_bWarnOnUnloads = dlg.m_bWarnOnUnload;
		softKey->SetIntegerValue(_T("WarnOnUnloads"), this->p_bWarnOnUnloads);
		
		// Free the registry key
		delete softKey;
	}

	return nResponse;
}
Пример #6
0
int CShellCommandDeleteValue::Execute(CConsole &rConsole, CArgumentParser& rArguments)
{
  rArguments.ResetArgumentIteration();
  TCHAR *pszCommandItself = rArguments.GetNextArgument();

  TCHAR *pszParameter;
  TCHAR *pszValueFull = NULL;
  BOOL blnHelp = FALSE;

  if ((_tcsnicmp(pszCommandItself,DV_CMD _T(".."),DV_CMD_LENGTH+2*sizeof(TCHAR)) == 0)||
      (_tcsnicmp(pszCommandItself,DV_CMD _T("\\"),DV_CMD_LENGTH+1*sizeof(TCHAR)) == 0))
  {
    pszValueFull = pszCommandItself + DV_CMD_LENGTH;
  }
  else if (_tcsnicmp(pszCommandItself,DV_CMD _T("/"),DV_CMD_LENGTH+1*sizeof(TCHAR)) == 0)
  {
    pszParameter = pszCommandItself + DV_CMD_LENGTH;
    goto CheckValueArgument;
  }

  while((pszParameter = rArguments.GetNextArgument()) != NULL)
  {
CheckValueArgument:
    if ((_tcsicmp(pszParameter,_T("/?")) == 0)
        ||(_tcsicmp(pszParameter,_T("-?")) == 0))
    {
      blnHelp = TRUE;
      break;
    }
    else if (!pszValueFull)
    {
      pszValueFull = pszParameter;
    }
    else
    {
      rConsole.Write(_T("Bad parameter: "));
      rConsole.Write(pszParameter);
      rConsole.Write(_T("\n"));
    }
  }

  CRegistryKey Key;
  TCHAR *pszValueNamePattern;
  const TCHAR *pszEmpty = _T("");
  const TCHAR *pszPath;

  if (blnHelp)
  {
    rConsole.Write(GetHelpString());
    return 0;
  }

  if (pszValueFull)
  {
    if (_tcscmp(pszValueFull,_T("\\")) == 0)
      goto CommandNAonRoot;

    TCHAR *pchSep = _tcsrchr(pszValueFull,_T('\\'));
    pszValueNamePattern = pchSep?(pchSep+1):(pszValueFull);
    pszPath = pchSep?pszValueFull:_T(".");

    if (pchSep)
      *pchSep = 0;
  }
  else
  {
    pszValueNamePattern = (TCHAR*)pszEmpty;
    pszPath = _T(".");
  }

  {
    size_t s = _tcslen(pszValueNamePattern);
    if (s && (pszValueNamePattern[0] == _T('\"'))&&(pszValueNamePattern[s-1] == _T('\"')))
    {
      pszValueNamePattern[s-1] = 0;
      pszValueNamePattern++;
    }
  }

  if (!m_rTree.GetKey(pszPath,KEY_QUERY_VALUE|KEY_SET_VALUE,Key))
  {
    rConsole.Write(m_rTree.GetLastErrorDescription());
    return 0;
  }

  if (!Key.IsRoot())
  {	// not root key ???
    TCHAR Buffer[254];
    DWORD dwMaxValueNameLength;
    LONG nError = Key.GetMaxValueNameLength(dwMaxValueNameLength);
    if (nError != ERROR_SUCCESS)
    {
      _stprintf(Buffer,_T("Cannot query info about %s key. Error is %u\n"),Key.GetKeyName(),(unsigned int)nError);
      rConsole.Write(Buffer);
      return 0;
    }

    TCHAR *pszValueName = new (std::nothrow) TCHAR[dwMaxValueNameLength];
    if (!pszValueName)
    {
      rConsole.Write("Out of memory.");
      return 0;
    }

    Key.InitValueEnumeration(pszValueName,dwMaxValueNameLength,NULL,0,NULL);

    while ((nError = Key.GetNextValue()) == ERROR_SUCCESS)
    {
      if (PatternMatch(pszValueNamePattern,pszValueName))
      {
        nError = Key.DeleteValue(pszValueName);
        if (nError != ERROR_SUCCESS)
        {
          _stprintf(Buffer,_T("Cannot delete value. Error is %u\n"),(unsigned int)nError);
          rConsole.Write(Buffer);
        }
        else
        {
          InvalidateCompletion();
        }
        Key.InitValueEnumeration(pszValueName,dwMaxValueNameLength,NULL,0,NULL); // reset iteration
      }
    }
  } // if (pKey)
  else
  {
CommandNAonRoot:
    rConsole.Write(DV_CMD COMMAND_NA_ON_ROOT);
  }

  return 0;
}
Пример #7
0
int CShellCommandOwner::Execute(CConsole &rConsole, CArgumentParser& rArguments)
{
	const TCHAR *pchKey = NULL;
	BOOL blnDo = TRUE;
	BOOL blnBadParameter = FALSE;
	BOOL blnHelp = FALSE;
	const TCHAR *pchParameter;
	DWORD dwError;

	rArguments.ResetArgumentIteration();
	const TCHAR *pchCommandItself = rArguments.GetNextArgument();

	if ((_tcsnicmp(pchCommandItself,OWNER_CMD _T(".."),OWNER_CMD_LENGTH+2*sizeof(TCHAR)) == 0)||
		(_tcsnicmp(pchCommandItself,OWNER_CMD _T("\\"),OWNER_CMD_LENGTH+1*sizeof(TCHAR)) == 0))
	{
		pchKey = pchCommandItself + OWNER_CMD_LENGTH;
	}
	else if (_tcsnicmp(pchCommandItself,OWNER_CMD _T("/"),OWNER_CMD_LENGTH+1*sizeof(TCHAR)) == 0)
	{
		pchParameter = pchCommandItself + OWNER_CMD_LENGTH;
		goto CheckOwnerArgument;
	}

	while((pchParameter = rArguments.GetNextArgument()) != NULL)
	{
CheckOwnerArgument:
		blnBadParameter = FALSE;
		if ((_tcsicmp(pchParameter,_T("/?")) == 0)
			||(_tcsicmp(pchParameter,_T("-?")) == 0))
		{
			blnHelp = TRUE;
			blnDo = pchKey != NULL;
		}
		else if (!pchKey)
		{
			pchKey = pchParameter;
			blnDo = TRUE;
		}
		else
		{
			blnBadParameter = TRUE;
		}
		if (blnBadParameter)
		{
			rConsole.Write(_T("Bad parameter: "));
			rConsole.Write(pchParameter);
			rConsole.Write(_T("\n"));
		}
	}

	CRegistryKey Key;

  if (!m_rTree.GetKey(pchKey?pchKey:_T("."),KEY_QUERY_VALUE|READ_CONTROL,Key))
  {
    rConsole.Write(m_rTree.GetLastErrorDescription());
    blnDo = FALSE;
  }

	if (blnHelp)
	{
		rConsole.Write(GetHelpString());
	}

	if (blnDo&&blnHelp) rConsole.Write(_T("\n"));

	if (!blnDo)
    return 0;

  if (Key.IsRoot())
  {	// root key
    rConsole.Write(OWNER_CMD COMMAND_NA_ON_ROOT);
    return 0;
  }

  PISECURITY_DESCRIPTOR pSecurityDescriptor = NULL;
  TCHAR *pchName = NULL, *pchDomainName = NULL;
  try
  {
    DWORD dwSecurityDescriptorLength;
    rConsole.Write(_T("Key : "));
    rConsole.Write(_T("\\"));
    rConsole.Write(Key.GetKeyName());
    rConsole.Write(_T("\n"));
    dwError = Key.GetSecurityDescriptorLength(&dwSecurityDescriptorLength);
    if (dwError != ERROR_SUCCESS) throw dwError;

    pSecurityDescriptor = (PISECURITY_DESCRIPTOR) new unsigned char [dwSecurityDescriptorLength];
    DWORD dwSecurityDescriptorLength1 = dwSecurityDescriptorLength;
    dwError = Key.GetSecurityDescriptor((SECURITY_INFORMATION)OWNER_SECURITY_INFORMATION,pSecurityDescriptor,&dwSecurityDescriptorLength1);
    if (dwError != ERROR_SUCCESS) throw dwError;
    PSID psidOwner;
    BOOL blnOwnerDefaulted;
    if (!GetSecurityDescriptorOwner(pSecurityDescriptor,&psidOwner,&blnOwnerDefaulted))
      throw GetLastError();
    if (psidOwner == NULL)
    {
      rConsole.Write(_T("Key has no owner."));
    }
    else
    {
      if (!IsValidSid(psidOwner))
      {
        rConsole.Write(_T("Key has invalid owner SID."));
      }
      else
      {
        rConsole.Write(_T("Key Owner: \n"));
        DWORD dwSIDStringSize = 0;
        BOOL blnRet = GetTextualSid(psidOwner,NULL,&dwSIDStringSize);
        ASSERT(!blnRet);
        ASSERT(GetLastError() == ERROR_INSUFFICIENT_BUFFER);
        TCHAR *pchSID = new TCHAR[dwSIDStringSize];
        if(!GetTextualSid(psidOwner,pchSID,&dwSIDStringSize))
        {
          dwError = GetLastError();
          ASSERT(dwError != ERROR_INSUFFICIENT_BUFFER);
          rConsole.Write(_T("Error "));
          TCHAR Buffer[256];
          rConsole.Write(_itoa(dwError,Buffer,10));
          rConsole.Write(_T("\nGetting string representation of SID\n"));
        }
        else
        {
          rConsole.Write(_T("\tSID: "));
          rConsole.Write(pchSID);
          rConsole.Write(_T("\n"));
        }
        delete [] pchSID;
        DWORD dwNameBufferLength, dwDomainNameBufferLength;
        dwNameBufferLength = 1024;
        dwDomainNameBufferLength = 1024;
        pchName = new TCHAR [dwNameBufferLength];
        pchDomainName = new TCHAR [dwDomainNameBufferLength];
        DWORD dwNameLength = dwNameBufferLength, dwDomainNameLength = dwDomainNameBufferLength;
        SID_NAME_USE Use;
        if (!LookupAccountSid(NULL,psidOwner,pchName,&dwNameLength,pchDomainName,&dwDomainNameLength,&Use))
          throw GetLastError();
        else
        {
          rConsole.Write(_T("\tOwner Domain: "));
          rConsole.Write(pchDomainName);
          rConsole.Write(_T("\n"));
          rConsole.Write(_T("\tOwner Name: "));
          rConsole.Write(pchName);
          rConsole.Write(_T("\n\tSID type: "));
          rConsole.Write(GetSidTypeName(Use));
          rConsole.Write(_T("\n"));
          rConsole.Write(_T("\tOwner defaulted: "));
          rConsole.Write(blnOwnerDefaulted?_T("Yes"):_T("No"));
          rConsole.Write(_T("\n"));
        }
        delete [] pchName;
        pchName = NULL;
        delete [] pchDomainName;
        pchDomainName = NULL;

      }
    }
    delete [] pSecurityDescriptor;
  }
  catch (DWORD dwError)
  {
    rConsole.Write(_T("Error "));
    TCHAR Buffer[256];
    rConsole.Write(_itoa(dwError,Buffer,10));
    rConsole.Write(_T("\n"));
    if (pchName) delete [] pchName;
    if (pchDomainName) delete [] pchDomainName;
    if (pSecurityDescriptor) delete [] pSecurityDescriptor;
  }

	return 0;
}
BOOL CDefaultDlg::OnInitDialog() {
	CDialog::OnInitDialog();
	CString				// Strings
		szMessage,		// MessageBox message resources
		szTitle,		// MessageBox title resources
		szLPath;		// This is where autofind will save the path it finds

	// Initialize Registry Access
	CRegistryKey *softKey = this->p_cReg.KeyCurrentUser()->CreateKey(_T("SOFTWARE\\6XGate Incorporated\\PalemoonPreload"));
	::OutputDebugString(_T("\r\nLoading Settings...\r\n"));
	
	// Load the timer configuration, save and use the default if not set
	softKey->GetIntegerValue(_T("PollInterval"), (ULONG*)&(this->p_nTimerInt));
	if (this->p_nTimerInt == 0) {
		::OutputDebugString(_T("Default timer Interval\r\n"));
		this->p_nTimerInt = 5000;
		softKey->SetIntegerValue(_T("PollInterval"), this->p_nTimerInt);
	}
	
	// Load the Warning configuration, save and use the default it not set
	if (softKey->GetIntegerValue(_T("WarnOnUnloads"), (ULONG*)&(this->p_bWarnOnUnloads)) != ERROR_SUCCESS)
		softKey->SetIntegerValue(_T("WarnOnUnloads"), this->p_bWarnOnUnloads);

	// Load the AutoFind configuration, then get Palemoon's path if AutoFind is enabled
	softKey->GetIntegerValue(_T("AutoFind"), (ULONG*)&(this->p_bAutoFindFF));
	if (this->p_bAutoFindFF && ::GetLatestPalemoonInstallDir(&szLPath)) {
		::OutputDebugString(_T("Using AutoFind\r\n"));

		// Remove the saved path since AutoFind found Palemoon's path
		softKey->DeleteValue(_T("Path"));
		this->p_szPalemoonPath = szLPath;		
		softKey->SetIntegerValue(_T("AutoFind"), TRUE);

	// If AutoFind is not enabled, or the path couldn't be found, use the manually entered path
	} else {
		::OutputDebugString(_T("Unable to use AutoFind, trying manually\r\n"));

		this->p_bAutoFindFF = FALSE;
		softKey->SetIntegerValue(_T("AutoFind"), FALSE);
		softKey->GetStringValue(_T("Path"), &(this->p_szPalemoonPath));
	}

	// If the path was not found by the manual setting or automatically, ask the user for it
	if (this->p_szPalemoonPath.IsEmpty()) {
		::OutputDebugString(_T("We didn't get the path, lets ask the user for on\r\n"));
		
		this->p_bTimer = FALSE;
		szMessage.LoadString(IDS_ENTERPATH); szTitle.LoadString(IDS_TRAYTIP);
		this->MessageBox (szMessage, szTitle, MB_OK);
		
		// Display the Options dialog box to ask the user for the path, or let the user enable AutoFind
		if (this->ShowPreloaderOptionsDlg() != IDOK) {
			::OutputDebugString(_T("The user cancelled\r\n"));
			szTitle.LoadString(IDS_ERROR_TITLE);
			szMessage.LoadString(IDS_NEEDPATH);

			// The user didn't enter the path, display a warning and end the program
			this->MessageBox (szMessage, szTitle, MB_OK);
			delete softKey;					// Free the key
			this->EndDialog(IDCANCEL);		// End the dialog
			return TRUE;					// And end the funcion
		}
	}

	// If the current profile directory can be found, then enable to parent.lock watcher code
	this->p_bUserLock = ::GetCurrentPalemoonProfile(&(this->p_szProfilePath));

	// Show the tray icon, free the key, and load Palemoon
	this->ShowTrayIcon();
	delete softKey;
	this->PreloadFF();

	// Set the timer
	this->SetTimer(1, this->p_nTimerInt, NULL);
	this->p_bTimer = TRUE;

	return TRUE;  // return TRUE unless you set the focus to a control
}
Пример #9
0
void CColumnDefMap::LoadSettings()
{
   if (!GetName().IsEmpty())
   {
      CAppRegistryKey appKey;
      CRegistryKey settings = appKey.createSubKey("Settings");

      if (settings.isOpen())
      {
         CRegistryKey registryKey = settings.createSubKey( GetName() );

         if (registryKey.isOpen())
         { 
            for (int i = 0; i < this->getSize(); i++)
            {
               CColumnDef *cd = this->getAt(i);
               CString title = cd->GetTitle();     // Column Name
               int *ptr = cd->GetColIndexPtr();
               int value;

               if (registryKey.getValue(title, value))
               {
                  *ptr = value;
               }
            }

            // Compensate
            // The number of fields present may have been reduced. This could
            // result in a hole in the numbering of active fields, as well as a column
            // number that is out of range for current list. Try to spot this and
            // if spotted then shuffle the fields down so we might preserve the
            // order for the rest of the fields. Failing this, teh Validate section
            // will just reassign everything to defaults.
            ///*rcf WELL ???

            // Validate
            // The values are column indices, nothing should be less
            // than zero, and not greater than the number of columns
            // minus 1. And no two should be alike. If there is an
            // error, then just reset the whole thing to sequentially
            // numbered.
            bool error = false;

            for (int i = 0; i < this->getSize() && !error; i++)
            {
               CColumnDef *cdI = this->getAt(i);
               int *valI = cdI->GetColIndexPtr();

               if (*valI < 0 || *valI >= this->getSize())
                  error = true;

               // Check no two alike
               for (int j = i+1; j < this->getSize() && !error; j++)
               {
                  CColumnDef *cdJ = this->getAt(j);
                  int *valJ = cdJ->GetColIndexPtr();

                  if (*valI == *valJ)
                     error = true;
               }
            }

            // If error then reset to sequential numbering
            if (error)
            {
               for (int i = 0; i < this->getSize(); i++)
               {
                  CColumnDef *cd = this->getAt(i);
                  int *valI = cd->GetColIndexPtr();
                  *valI = i;
               }
            }


         }
      }
   }
}
Пример #10
0
int CShellCommandValue::Execute(CConsole &rConsole, CArgumentParser& rArguments)
{
	rArguments.ResetArgumentIteration();
	TCHAR *pchCommandItself = rArguments.GetNextArgument();

	TCHAR *pchParameter;
	TCHAR *pchValueFull = NULL;
	BOOL blnUnicodeDump = FALSE;
	BOOL blnBadParameter = FALSE;
	BOOL blnHelp = FALSE;
	LONG nError;
	DWORD dwValueSize;
	DWORD dwType = REG_NONE;
	BYTE *pDataBuffer = NULL;
	TCHAR *pchFilename = NULL;

	if ((_tcsnicmp(pchCommandItself,VALUE_CMD _T(".."),VALUE_CMD_LENGTH+2*sizeof(TCHAR)) == 0)||
		(_tcsnicmp(pchCommandItself,VALUE_CMD _T("\\"),VALUE_CMD_LENGTH+1*sizeof(TCHAR)) == 0))
	{
		pchValueFull = pchCommandItself + VALUE_CMD_LENGTH;
	}
	else if (_tcsnicmp(pchCommandItself,VALUE_CMD _T("/"),VALUE_CMD_LENGTH+1*sizeof(TCHAR)) == 0)
	{
		pchParameter = pchCommandItself + VALUE_CMD_LENGTH;
		goto CheckValueArgument;
	}

	while((pchParameter = rArguments.GetNextArgument()) != NULL)
	{
CheckValueArgument:
		blnBadParameter = FALSE;
		if ((_tcsicmp(pchParameter,_T("/?")) == 0)
			||(_tcsicmp(pchParameter,_T("-?")) == 0))
		{
			blnHelp = TRUE;
			break;
		}
		else if (_tcsicmp(pchParameter,_T("/u")) == 0)
		{
			blnUnicodeDump = TRUE;
		}
		else if ((*pchParameter == _T('/'))&&(*(pchParameter+1) == _T('f')))
		{
			pchFilename = pchParameter+2;
		}
		else if (!pchValueFull)
		{
			pchValueFull = pchParameter;
		}
		else
		{
			blnBadParameter = TRUE;
		}
		if (blnBadParameter)
		{
			rConsole.Write(_T("Bad parameter: "));
			rConsole.Write(pchParameter);
			rConsole.Write(_T("\n"));
		}
	}

	CRegistryKey Key;
	TCHAR *pchValueName;
	const TCHAR *pszEmpty = _T("");
	const TCHAR *pszPath;

	if (blnHelp)
	{
		rConsole.Write(GetHelpString());

		if (pDataBuffer)
			delete pDataBuffer;

		return 0;
	}

	if (pchValueFull)
	{
		if (_tcscmp(pchValueFull,_T("\\")) == 0)
			goto ValueCommandNAonRoot;

		TCHAR *pchSep = _tcsrchr(pchValueFull,_T('\\'));
		pchValueName = pchSep?(pchSep+1):(pchValueFull);
		pszPath = pchSep?pchValueFull:_T(".");

		//if (_tcsrchr(pchValueName,_T('.')))
		//{
		//	pchValueName = _T("");
		//	pchPath = pchValueFull;
		//}
		//else
		if (pchSep)
			*pchSep = 0;
	}
	else
	{
		pchValueName = (TCHAR*)pszEmpty;
		pszPath = _T(".");
	}

  if (!m_rTree.GetKey(pszPath,KEY_READ,Key))
  {
    rConsole.Write(m_rTree.GetLastErrorDescription());
    goto SkipValueCommand;
  }

	if (Key.IsRoot())
    goto ValueCommandNAonRoot;

  {
    rConsole.Write(_T("Value name : \""));
    rConsole.Write(_T("\\"));
    rConsole.Write(Key.GetKeyName());
    size_t l = _tcslen(pchValueName);
    if (l&&
        (*pchValueName == _T('\"'))&&
        (pchValueName[l-1] == _T('\"')))
    {
      pchValueName[l-1] = 0;
      pchValueName++;
    }
    rConsole.Write(pchValueName);
    rConsole.Write(_T("\"\n"));

    nError = Key.GetValue(pchValueName,NULL,NULL,&dwValueSize);
    if (nError == ERROR_SUCCESS)
    {
      pDataBuffer = new BYTE [dwValueSize];
      Key.GetValue(pchValueName,&dwType,pDataBuffer,&dwValueSize);
      rConsole.Write(_T("Value type : "));
      rConsole.Write(CRegistryKey::GetValueTypeName(dwType));
      rConsole.Write(_T("\nValue data : "));
      switch(dwType)
      {
      case REG_DWORD_LITTLE_ENDIAN:
        {
          TCHAR Buffer[3];
          rConsole.Write(_T("0x"));
          for (unsigned int i = 0 ; i < dwValueSize ; i++)
          {
            _stprintf(Buffer,_T("%02X"),*(pDataBuffer+((dwValueSize-1)-i)));
            rConsole.Write(Buffer);
          }
        }
        rConsole.Write(_T("\n"));
        break;
      case REG_DWORD_BIG_ENDIAN:
        {
          TCHAR Buffer[3];
          rConsole.Write(_T("0x"));
          for (unsigned int i = 0 ; i < dwValueSize ; i++)
          {
            _stprintf(Buffer,_T("%02X"),*(pDataBuffer+i));
            rConsole.Write(Buffer);
          }
        }
        rConsole.Write(_T("\n"));
        break;
      case REG_LINK:
        break;
      case REG_MULTI_SZ:
        {
          TCHAR *pchCurrentString = (TCHAR *)pDataBuffer;
          rConsole.Write(_T("\n"));
          while(*pchCurrentString)
          {
            rConsole.Write(_T("\""));
            rConsole.Write(pchCurrentString);
            rConsole.Write(_T("\"\n"));
            pchCurrentString += _tcslen(pchCurrentString)+1;
          }
        }
        break;
      case REG_RESOURCE_LIST:
        break;
      case REG_SZ:
      case REG_EXPAND_SZ:
        rConsole.Write(_T("\""));
        rConsole.Write((TCHAR *)pDataBuffer);
        rConsole.Write(_T("\"\n"));
        break;
      case REG_BINARY:
      default:
        {
          TCHAR Buffer[256];
          DWORD i, j;
          for (i = 0 ; i < dwValueSize ; i++)
          {
            if (i%16 == 0)
            {	// ok this is begining of line
              rConsole.Write(_T("\n"));
              // print offset
              _stprintf(Buffer,_T("0x%08X  "),(unsigned int)i);
              rConsole.Write(Buffer);
            }
            else if (i%8 == 0)
            {	// this is the additional space between 7th and 8th byte in current line
              rConsole.Write(_T(" "));
            }

            // print current byte
            unsigned int n = *(pDataBuffer+i);
            _stprintf(Buffer,_T("%02X "),n);
            rConsole.Write(Buffer);

            if (i && (i%16 == 15))
            {	// if this is the last byte in line
              // Dump text representation
              for (j = i-15; j <= i; j += blnUnicodeDump?2:1)\
                  {
                    if ((j%8 == 0)&&(j%16 != 0))
                    {	// this is the additional space between 7th and 8th byte in current line
                      rConsole.Write(_T(" "));
                    }
                    ASSERT(i-j < 16);
                    // write current char representation
                    if (blnUnicodeDump)
                    {
                      ASSERT(j%2 == 0);
                      wchar_t ch = *(TCHAR *)(pDataBuffer+j);

                      _stprintf(Buffer,
#ifdef _UNICODE
                                _T("%c"),
#else
                                // g++ may print warnings here (warning: __wchar_t format, different type arg (arg 3))
                                // %C in format string is a Microsoft extension.
                                _T("%C"),
#endif
                                iswprint(ch)?ch:L'.');
                    }
                    else
                    {
                      unsigned char ch = *(pDataBuffer+j);

                      _stprintf(Buffer,
#ifdef _UNICODE
                                // g++ may print warnings here (warning: __wchar_t format, different type arg (arg 3))
                                // %C in format string is a Microsoft extension.
                                _T("%C"),
#else
                                _T("%c"),
#endif
                                isprint(ch)?ch:'.');
                    }
                    rConsole.Write(Buffer);
                  }	// for
            }	// if
          }	// for

          // print text representation of last line if it is not full (it have less than 16 bytes)
          // k is pseudo offset
          for (DWORD k = i; k%16 != 0; k++)
          {
            if (k%8 == 0)
            {	// this is the additional space between 7th and 8th byte in current line
              rConsole.Write(_T(" "));
            }
            _tcscpy(Buffer,_T("   "));	// the replacement of two digit of current byte + spacing
            rConsole.Write(Buffer);
            if (k && (k%16 == 15))
            {	// if this is the last byte in line
              ASSERT((k-15)%16 == 0);	// k-15 must point at begin of last line
              for (j = k-15; j < i; j += blnUnicodeDump?2:1)
              {
                if (blnUnicodeDump&&(j+1 >= i))
                {	// ok, buffer size is odd number, so we don't display last byte.
                  ASSERT(j+1 == i);
                  break;
                }
                if ((j%8 == 0)&&(j%16 != 0))
                {	// this is the additional space between 7th and 8th byte in current line
                  rConsole.Write(_T(" "));
                }

                // write current char representation
                if (blnUnicodeDump)
                {
                  ASSERT(j%2 == 0);
                  wchar_t ch = *(TCHAR *)(pDataBuffer+j);

                  _stprintf(Buffer,
#ifdef _UNICODE
                            _T("%c"),
#else
                            // g++ may print warnings here (warning: __wchar_t format, different type arg (arg 3))
                            // %C in format string is a Microsoft extension.
                            _T("%C"),
#endif
                            iswprint(ch)?ch:L'.');
                }
                else
                {
                  unsigned char ch = *(pDataBuffer+j);

                  _stprintf(Buffer,
#ifdef _UNICODE
                            // g++ may print warnings here (warning: __wchar_t format, different type arg (arg 3))
                            // %C in format string is a Microsoft extension.
                            _T("%C"),
#else
                            _T("%c"),
#endif
                            isprint(ch)?ch:'.');
                }
                rConsole.Write(Buffer);
              } // for
            } // if
          } // for
        } // default:
        rConsole.Write(_T("\n"));
      } // switch
      rConsole.Write(_T("\n"));

      if (pchFilename)
      {
        rConsole.Write(_T("Exporting value data to "));
        rConsole.Write(pchFilename);
        rConsole.Write(_T(" ...\n"));

        HANDLE hFile = CreateFile(pchFilename,GENERIC_WRITE,0,NULL,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL);
        if (hFile == INVALID_HANDLE_VALUE)
        {
          rConsole.Write(_T("Cannot create new file "));
          rConsole.Write(pchFilename);
          rConsole.Write(_T("\n"));
          goto SkipValueCommand;
        }

        DWORD dwBytesWritten;
        if (!WriteFile(hFile,pDataBuffer,dwValueSize,&dwBytesWritten,NULL))
        {
          rConsole.Write(_T("Error writting file.\n"));
          VERIFY(CloseHandle(hFile));
          goto SkipValueCommand;
        }

        ASSERT(dwBytesWritten == dwValueSize);
        VERIFY(CloseHandle(hFile));
      }
    }
    else
    {
      rConsole.Write(_T("Error "));
      TCHAR Buffer[256];
      rConsole.Write(_itoa(nError,Buffer,10));
      rConsole.Write(_T("\n"));
      if (nError == ERROR_FILE_NOT_FOUND)
      {
        rConsole.Write(_T("(System cannot find the value specified)\n"));
      }
    }
  }

SkipValueCommand:
	if (pDataBuffer)
		delete[] pDataBuffer;
	return 0;
ValueCommandNAonRoot:
	rConsole.Write(VALUE_CMD COMMAND_NA_ON_ROOT);
  return 0;
}
Пример #11
0
int CShellCommandSetValue::Execute(CConsole &rConsole, CArgumentParser& rArguments)
{
  LONG nError;

	rArguments.ResetArgumentIteration();
	TCHAR *pszCommandItself = rArguments.GetNextArgument();

	TCHAR *pszParameter;
	TCHAR *pszValueFull = NULL;
	TCHAR *pszValueData = NULL;
	BOOL blnBadParameter = FALSE;
	BOOL blnHelp = FALSE;
	DWORD dwValueSize = 0;
	DWORD dwType = REG_NONE;
	BYTE *pDataBuffer = NULL;

	if ((_tcsnicmp(pszCommandItself,SET_VALUE_CMD _T(".."),SET_VALUE_CMD_LENGTH+2*sizeof(TCHAR)) == 0)||
		(_tcsnicmp(pszCommandItself,SET_VALUE_CMD _T("\\"),SET_VALUE_CMD_LENGTH+1*sizeof(TCHAR)) == 0))
	{
		pszValueFull = pszCommandItself + SET_VALUE_CMD_LENGTH;
	}
	else if (_tcsnicmp(pszCommandItself,SET_VALUE_CMD _T("/"),SET_VALUE_CMD_LENGTH+1*sizeof(TCHAR)) == 0)
	{
		pszParameter = pszCommandItself + SET_VALUE_CMD_LENGTH;
		goto CheckValueArgument;
	}

	while((pszParameter = rArguments.GetNextArgument()) != NULL)
	{
CheckValueArgument:
		blnBadParameter = FALSE;
		if (((*pszParameter == _T('/'))||(*pszParameter == _T('-')))
			&&(*(pszParameter+1) == _T('?')))
		{
			blnHelp = TRUE;
		}
		else if (dwType == REG_NONE)
		{
			if (_tcsicmp(pszParameter,_T("b")) == 0)
			{
				dwType = REG_BINARY;
			}
			else if (_tcsicmp(pszParameter,_T("dw")) == 0)
			{
				dwType = REG_DWORD;
			}
			else if (_tcsicmp(pszParameter,_T("dwle")) == 0)
			{
				dwType = REG_DWORD_LITTLE_ENDIAN;
			}
			else if (_tcsicmp(pszParameter,_T("dwbe")) == 0)
			{
				dwType = REG_DWORD_BIG_ENDIAN;
			}
			else if (_tcsicmp(pszParameter,_T("sz")) == 0)
			{
				dwType = REG_SZ;
			}
			else if (_tcsicmp(pszParameter,_T("esz")) == 0)
			{
				dwType = REG_EXPAND_SZ;
			}
			else
			{
				blnBadParameter = TRUE;
			}
		}
		else if (pszValueData == NULL)
		{
			pszValueData = pszParameter;
		}
		else if (!pszValueFull)
		{
			pszValueFull = pszParameter;
		}
		else
		{
			blnBadParameter = TRUE;
		}
		if (blnBadParameter)
		{
			rConsole.Write(_T("Bad parameter: "));
			rConsole.Write(pszParameter);
			rConsole.Write(_T("\n"));
		}
	}

	if (!pszValueData)
		blnHelp = TRUE;

	CRegistryKey Key;
	TCHAR *pszValueName;
	const TCHAR *pszEmpty = _T("");
	const TCHAR *pszPath;

	if (blnHelp)
	{
		rConsole.Write(GetHelpString());

		if (pDataBuffer)
			delete pDataBuffer;

		return 0;
	}

	if (pszValueFull)
	{
		if (_tcscmp(pszValueFull,_T("\\")) == 0)
			goto CommandNAonRoot;

		TCHAR *pchSep = _tcsrchr(pszValueFull,_T('\\'));
		pszValueName = pchSep?(pchSep+1):(pszValueFull);
		pszPath = pchSep?pszValueFull:_T(".");

		//if (_tcsrchr(pszValueName,_T('.')))
		//{
		//	pszValueName = _T("");
		//	pszPath = pszValueFull;
		//}
		//else
		if (pchSep)
			*pchSep = 0;
	}
	else
	{
		pszValueName = (TCHAR*)pszEmpty;
		pszPath = _T(".");
	}

  if (!m_rTree.GetKey(pszPath,KEY_SET_VALUE,Key))
  {
    rConsole.Write(m_rTree.GetLastErrorDescription());
    goto SkipCommand;
  }

	if (Key.IsRoot())
    goto CommandNAonRoot;

  switch (dwType)
  {
  case REG_BINARY:
    {
      HANDLE hFile;
      DWORD dwBytesReaded;
      hFile = CreateFile(pszValueData,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,0,NULL);
      if (hFile == INVALID_HANDLE_VALUE)
      {
        rConsole.Write(_T("Cannot open file "));
        rConsole.Write(pszValueData);
        rConsole.Write(_T("\n"));
        goto SkipCommand;
      }
      dwValueSize = GetFileSize(hFile,NULL);
      if (dwValueSize == (DWORD)-1)	// ok, that's right, we compare signed with unsigned here.
        // GetFileSize is documented and declared to return DWORD.
        // Error is indicated by checking if return is -1. Design->documentation bug ???
      {
        rConsole.Write(_T("Cannot get size of file "));
        rConsole.Write(pszValueData);
        rConsole.Write(_T("\n"));
        VERIFY(CloseHandle(hFile));
        goto SkipCommand;
      }
      pDataBuffer = new BYTE [dwValueSize];
      if (!pDataBuffer)
      {
        rConsole.Write(_T("Cannot load file into memory. Out of memory.\n"));
        VERIFY(CloseHandle(hFile));
        goto SkipCommand;
      }
      if (!ReadFile(hFile,pDataBuffer,dwValueSize,&dwBytesReaded,NULL))
      {
        rConsole.Write(_T("Cannot load file into memory. Error reading file.\n"));
        VERIFY(CloseHandle(hFile));
        goto SkipCommand;
      }

      VERIFY(CloseHandle(hFile));
      ASSERT(dwBytesReaded == dwValueSize);
    }
    break;
  case REG_DWORD_LITTLE_ENDIAN:
  case REG_DWORD_BIG_ENDIAN:
    dwValueSize = 4;
    pDataBuffer = (BYTE *) new BYTE [dwValueSize];
    if (!StringToDWORD(*(DWORD *)pDataBuffer,pszValueData))
    {
      rConsole.Write(_T("Cannot convert "));
      rConsole.Write(pszValueData);
      rConsole.Write(_T(" to DWORD \n"));
      goto SkipCommand;
    }
    if (dwType == REG_DWORD_BIG_ENDIAN)
    {
      unsigned char nByte;
      nByte = *pDataBuffer;
      *pDataBuffer = *(pDataBuffer+3);
      *(pDataBuffer+3) = nByte;
      nByte = *(pDataBuffer+1);
      *(pDataBuffer+1) = *(pDataBuffer+2);
      *(pDataBuffer+2) = nByte;
    }
    break;
  case REG_SZ:
  case REG_EXPAND_SZ:
    dwValueSize = _tcslen(pszValueData)+1;
    if (*pszValueData == _T('\"'))
    {
      dwValueSize -= 2;
      *(pszValueData+dwValueSize) = 0;
      pszValueData++;
    }
    dwValueSize *= sizeof(TCHAR);
    pDataBuffer = (BYTE *) new BYTE [dwValueSize];

    {
      const TCHAR *pchSrc = pszValueData;
      TCHAR *pchDest = (TCHAR *)pDataBuffer;
      while(*pchSrc)
      {
        if (pchSrc[0] == _T('^'))
        {
          if (pchSrc[1] == _T('a'))
            *pchDest = _T('\a');
          else if (pchSrc[1] == _T('b'))
            *pchDest = _T('\b');
          else if (pchSrc[1] == _T('f'))
            *pchDest = _T('\f');
          else if (pchSrc[1] == _T('n'))
            *pchDest = _T('\n');
          else if (pchSrc[1] == _T('r'))
            *pchDest = _T('\r');
          else if (pchSrc[1] == _T('t'))
            *pchDest = _T('\t');
          else
            *pchDest = pchSrc[1];

          pchSrc +=2;
          pchDest++;
          dwValueSize--;
        }
        else
        {
          *pchDest = *pchSrc;
          pchSrc++;
          pchDest++;
        }
      }
      *pchDest = _T('\0');
    }
    break;
  default:
    ASSERT(FALSE);
  }

  {
    size_t s = _tcslen(pszValueName);
    if (s && (pszValueName[0] == _T('\"'))&&(pszValueName[s-1] == _T('\"')))
    {
      pszValueName[s-1] = 0;
      pszValueName++;
    }
  }

  nError = Key.SetValue(pszValueName,dwType,pDataBuffer,dwValueSize);
  if (nError != ERROR_SUCCESS)
  {
    char Buffer[254];
    _stprintf(Buffer,_T("Cannot set value. Error is %u\n"),(unsigned int)nError);
    rConsole.Write(Buffer);
  }
  else
  {
    InvalidateCompletion();
  }

SkipCommand:
	if (pDataBuffer)
		delete[] pDataBuffer;
	return 0;

CommandNAonRoot:
  rConsole.Write(SET_VALUE_CMD COMMAND_NA_ON_ROOT);
  return 0;
}
Пример #12
0
LONG testReg2()
{
	LONG lResult = 0;
	
	CRegistryKey regKey;
	
	regKey.Create(HKEY_LOCAL_MACHINE, THE_REG_SUB_KEYW);
	
	if(lResult != 0)
	{
		return lResult;
	}
	std::wstring strValue;
	
	lResult = regKey.GetString(THE_VALUE_NAMEW, strValue);
	if(lResult == 0)
	{
		wprintf(L"Original value: %s=%s\n", THE_VALUE_NAMEW, strValue.c_str());
	}
	else
	{
		wprintf(L"1: The value %s doesn't exist\n", THE_VALUE_NAMEW);
	}
	
	lResult = regKey.SetString(THE_VALUE_NAMEW, L"test%M2%_456", REG_EXPAND_SZ);
	if(lResult != 0)
	{
		return lResult;
	}
	
	
	lResult = regKey.GetString(THE_VALUE_NAMEW, strValue);
	if(lResult == 0)
	{
		wprintf(L"Setted value: %s=%s\n", THE_VALUE_NAMEW, strValue.c_str());
	}
	else
	{
		wprintf(L"2: The value %s doesn't exist\n", THE_VALUE_NAMEW);
	}
	
	regKey.Delete(THE_VALUE_NAMEW);
	
	DWORD dwValue = 0;
	lResult = regKey.GetDWORD(THE_DWORD_NAMEW, &dwValue);
	
	if(lResult == 0)
	{
		wprintf(L"Original value: %s=%08X\n", THE_DWORD_NAMEW, dwValue);
	}
	else
	{
		wprintf(L"1: The value %s doesn't exist\n", THE_DWORD_NAMEW);
	}
	
	dwValue = 0x8134569F;
	lResult = regKey.SetDWORD(THE_DWORD_NAMEW, dwValue);
	if(lResult != 0)
	{
		return lResult;
	}
	dwValue = 0;
	
	lResult = regKey.GetDWORD(THE_DWORD_NAMEW, &dwValue);
	if(lResult == 0)
	{
		wprintf(L"Setted value: %s=%08X\n", THE_DWORD_NAMEW, dwValue);
	}
	else
	{
		wprintf(L"2: The value %s doesn't exist\n", THE_DWORD_NAMEW);
	}
	
	regKey.Delete(THE_DWORD_NAMEW);
	
	
	return lResult;
}