bool SplitFilenameString_Priv (const char* pFilename, const size_t Length, CSString& Path, CSString& BaseFilename, CSString& Extension)
{
	const char* pParse = pFilename;
	int Index = Length - 1;
	int ExtensionIndex;
	
	Extension.Empty();
	BaseFilename.Empty();
	Path.Empty();

	if (Length == 0) return true;

	while (Index >= 0)
	{
		if (pParse[Index] == '.')
		{
			Extension = pParse + Index + 1;
			ExtensionIndex = Index;
			break;
		}
		else if (pParse[Index] == '\\' || pParse[Index] == '/' || pParse[Index] == ':')
		{
			ExtensionIndex = Length;
			Extension.Empty();
			break;
		}

		--Index;
	}

	while (Index >= 0)
	{
		if (pParse[Index] == '\\' || pParse[Index] == '/' || pParse[Index] == ':')
		{
			BaseFilename = pParse + Index + 1;
			BaseFilename.Truncate(ExtensionIndex - Index - 1);
			Path.Copy(pFilename, Index + 1);
			return true;
		}

		--Index;
	}

	BaseFilename.Copy(pFilename, ExtensionIndex - Index - 1);
	return true;
}
/*===========================================================================
 *
 * Class char* CSrResourceFolder Method - const GetFullName (void);
 *
 *=========================================================================*/
const char* CSrResourceFolder::GetFullName (void) {
  static CSString s_Buffer;

  if (m_pParent != NULL) {
    s_Buffer = m_pParent->GetFullName();
  }
  else {
    s_Buffer.Empty();
  }
  
  if (!m_Name.IsEmpty()) {
    s_Buffer += GetName();
    s_Buffer += "\\";
  }

  return (s_Buffer);
}
/*===========================================================================
 *
 * Function - bool GetSrInstallPath (Buffer);
 *
 * Attempt to find Skyrim's install path in the registry. On success true
 * is returned and the path copied to the given buffer. On error false is
 * returned.
 *
 * HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Bethesda Softworks\Skyrim
 *
 *=========================================================================*/
bool GetSrInstallPath (CSString& OutputBuffer) 
{
  HKEY  hKey;
  BYTE  Buffer[300];
  DWORD Size = 256;
  DWORD Type;
  int   Result;

		/* Use the manual install path if set */
  if (!g_SrManualInstallPath.IsEmpty())
  {
	  OutputBuffer = g_SrManualInstallPath;
	  return true;
  }

  OutputBuffer.Empty();
  Result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, SR_REG_SUBKEY, 0, KEY_READ, &hKey);

  if (Result != ERROR_SUCCESS) 
  {
	  Result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, SR_REG_SUBKEY64, 0, KEY_READ, &hKey);

	  if (Result != ERROR_SUCCESS)
	  {
		AddSrGeneralError("Failed to find Skyrim's install path in the Windows registry!");
		return (false);
	  }
  }

  Result = RegQueryValueEx(hKey, SR_REG_INSTALLPATH, NULL, &Type, Buffer, &Size);

  if (Result == ERROR_SUCCESS && Type == REG_SZ) 
  {
    OutputBuffer = (char *)Buffer;
  }
  else 
  {
    AddSrGeneralError("Failed to find Skyrim's install path in the Windows registry!");
    RegCloseKey(hKey);
    return (false);
  }
     
  RegCloseKey(hKey);
  return (true);
}
bool SrFindSubDataPath (const char* pFilename, CSString& OutputPath, CSString& OutputFilename, CSString& OutputExtension)
{
	CSString Path;
	int      Index;

	SplitFilenameString(pFilename, Path, OutputFilename, OutputExtension);

	Index = Path.FindRI("\\data\\");

	if (Index >= 0)
		++Index;
	else if (Index < 0 && Path.StartsWithI("data\\")) 
		Index = 0;

	if (Index < 0) 
	{
		OutputPath.Empty();
		return false;
	}

	OutputPath.Copy(Path.c_str() + Index + 5, Path.GetLength() - Index - 5);
	return true;
}
Beispiel #5
0
int CTextConsole::OnConsoleKey( CSString & sText, tchar nChar, bool fEcho )
{
    ADDTOCALLSTACK("CTextConsole::OnConsoleKey");
    // eventaully we should call OnConsoleCmd
    // RETURN:
    //  0 = dump this connection.
    //  1 = keep processing.
    //  2 = process this.

    if ( sText.GetLength() >= SCRIPT_MAX_LINE_LEN )
    {
        commandtoolong:
        SysMessage( "Command too long\n" );

        sText.Empty();
        return 0;
    }

    if ( nChar == '\r' || nChar == '\n' )
    {
        // Ignore the character if we have no text stored
        if (!sText.GetLength())
            return 1;

        if ( fEcho )
        {
            SysMessage("\n");
        }
        return 2;
    }
    else if ( nChar == 9 )			// TAB (auto-completion)
    {
        lpctstr p = nullptr;
        lpctstr tmp = nullptr;
        size_t inputLen = 0;
        bool matched(false);

        //	extract up to start of the word
        p = sText.GetPtr() + sText.GetLength();
        while (( p >= sText.GetPtr() ) && ( *p != '.' ) && ( *p != ' ' ) && ( *p != '/' ) && ( *p != '=' )) p--;
        p++;
        inputLen = strlen(p);

        // search in the auto-complete list for starting on P, and save coords of 1st and Last matched
        CSStringListRec	*firstmatch = nullptr, *lastmatch = nullptr;
        CSStringListRec	*curmatch = nullptr, *nextmatch = nullptr;	// the one that should be set
        for ( curmatch = g_AutoComplete.GetHead(); curmatch != nullptr; curmatch = nextmatch )
        {
            nextmatch = curmatch->GetNext();
            if ( !strnicmp(curmatch->GetPtr(), p, inputLen) )	// matched
            {
                if ( firstmatch == nullptr )
                    firstmatch = lastmatch = curmatch;
                else
                    lastmatch = curmatch;
            }
            else if ( lastmatch )   // if no longer matches - save time by instant quit
                break;
        }

        if (( firstmatch != nullptr ) && ( firstmatch == lastmatch ))	// there IS a match and the ONLY
        {
            tmp = firstmatch->GetPtr() + inputLen;
            matched = true;
        }
        else if ( firstmatch != nullptr )						// also make SE (if SERV/SERVER in dic) to become SERV
        {
            p = tmp = firstmatch->GetPtr();
            tmp += inputLen;
            inputLen = strlen(p);
            matched = true;
            for ( curmatch = firstmatch->GetNext(); curmatch != lastmatch->GetNext(); curmatch = curmatch->GetNext() )
            {
                if (strnicmp(curmatch->GetPtr(), p, inputLen) != 0)	// mismatched
                {
                    matched = false;
                    break;
                }
            }
        }

        if ( matched )
        {
            if ( fEcho )
                SysMessage(tmp);

            sText += tmp;
            if ( sText.GetLength() > SCRIPT_MAX_LINE_LEN )
                goto commandtoolong;
        }
        return 1;
    }

    if ( fEcho )
    {
        // Echo
        tchar szTmp[2];
        szTmp[0] = nChar;
        szTmp[1] = '\0';
        SysMessage( szTmp );
    }

    if ( nChar == 8 )
    {
        if ( sText.GetLength())	// back key
        {
            sText.SetLength( sText.GetLength() - 1 );
        }
        return 1;
    }

    sText += nChar;
    return 1;
}