April 28, 2024, 11:44:09 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


GetAuroraDir

Started by Parker, January 11, 2006, 07:11:55 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Parker

In IBasic Pro, we could easily get the command paks location, helpfiles, whatever we wanted, since we had fletchie's GetIBProDir() function. That function enabled us to write command paks using his installer, and it worked by reading the BIN key under HKEY_CURRENT_USER\Software\Pyxia\IBasic Pro\PATHS. Since the Aurora IDE works in a similar way, we can read the BIN key of HKCU\Software\IonicWind\Aurora\PATHS and get the path to the 'bin' directory of Aurora. If you need any others, just chop off the part after the last '\' character and add to it.

This code includes an example of using the function.
#use "advapi32.lib"
declare import, RegOpenKeyEx alias RegOpenKeyExA(
unsigned int hKey,
string lpSubKey,
unsigned int ulOptions,
unsigned int samDesired,
pointer phkResult
),unsigned int;

declare import, RegCloseKey(
unsigned int hKey
),unsigned int;

declare import, RegQueryValueEx alias RegQueryValueExA(
  unsigned int hKey,
  string lpValueName,
  unsigned int *lpReserved,
  unsigned int *lpType,
  byte *lpData,
  unsigned int *lpcbData
);

#define HKEY_CURRENT_USER 0x80000001
#define KEY_READ 0x20019
#define KEY_QUERY_VALUE 0x0001
#define REG_SZ 1
#define RRF_RT_REG_SZ 0x00000002
#define ERROR_SUCCESS 0

global sub GetAuroraDir(string directory)
{
// The key we need is under HKCU\Software\IonicWind\Aurora\PATHS -- it is called BIN.
unsigned int key, size=255, type;
string value;
RegOpenKeyEx(
HKEY_CURRENT_USER,
"Software\\IonicWind\\Aurora\\PATHS",
0,
KEY_READ | KEY_QUERY_VALUE,
key);

if( key = 0 )
{
directory = "";
return;
}

if( RegQueryValueEx(key, "BIN", NULL, type, value, size) <> ERROR_SUCCESS )
{
directory = "";
RegCloseKey(key);
return;
}
if (type <> REG_SZ)
{
directory = "";
RegCloseKey(key);
return;
}

directory = value;
RegCloseKey(key);
return;
}

global sub main()
{
string dir;
GetAuroraDir(dir);
messagebox(0, dir, "success");
return;
}


Coming soon: An easy compiler for Aurora, a command line utility that allows you to compile your source files with one simple command and handles piping the output to the STDOUT, perfect for 3rd part IDEs ;)

Also a note for Paul: The GetAuroraDir function only works when I add the return statement. I don't think the default return behaivor has been implemented yet for a "global sub" declaration.

Ionic Wind Support Team

Actually it is because you have more than one return statement.  Since the compiler can't know if your code is correct it assumes you know what your doing ;)

The only time it will add the return statement is if one wasn't seen and it reached the end of the subroutine.
Ionic Wind Support Team

Parker

January 12, 2006, 08:17:35 PM #2 Last Edit: January 12, 2006, 08:22:12 PM by Parker
Thanks, I get it now. The return is no problem, I just didn't understand the behaivor.

Anyways, the function now subtracts the 'bin' part for you.
#use "advapi32.lib"
declare import, RegOpenKeyEx alias RegOpenKeyExA(
unsigned int hKey,
string lpSubKey,
unsigned int ulOptions,
unsigned int samDesired,
pointer phkResult
),unsigned int;

declare import, RegCloseKey(
unsigned int hKey
),unsigned int;

declare import, RegQueryValueEx alias RegQueryValueExA(
  unsigned int hKey,
  string lpValueName,
  unsigned int *lpReserved,
  unsigned int *lpType,
  byte *lpData,
  unsigned int *lpcbData
);

#define HKEY_CURRENT_USER 0x80000001
#define KEY_READ 0x20019
#define KEY_QUERY_VALUE 0x0001
#define REG_SZ 1
#define RRF_RT_REG_SZ 0x00000002
#define ERROR_SUCCESS 0

global sub GetAuroraDir(string directory)
{
// The key we need is under HKCU\Software\IonicWind\Aurora\PATHS -- it is called BIN.
unsigned int key, size=255, type;
string value;
RegOpenKeyEx(
HKEY_CURRENT_USER,
"Software\\IonicWind\\Aurora\\PATHS",
0,
KEY_READ | KEY_QUERY_VALUE,
key);

if( key = 0 )
{
directory = "";
return;
}

if( RegQueryValueEx(key, "BIN", NULL, type, value, size) <> ERROR_SUCCESS )
{
directory = "";
RegCloseKey(key);
return;
}
if (type <> REG_SZ)
{
directory = "";
RegCloseKey(key);
return;
}

// Remove the 'bin' part.
for (i = len(value); i >= 0; i--)
{
if (value[i] = 92) break;
}
directory = left$(value, i+1);
RegCloseKey(key);
return;
}