Example #1
0
void regInit(const char *path, bool force)
{
	if( regEnabled ) {
  DWORD disp = 0;
  LONG res = RegCreateKeyEx(HKEY_CURRENT_USER,
                            "Software\\Emulators\\VisualBoyAdvance",
                            0,
                            "",
                            REG_OPTION_NON_VOLATILE,
                            KEY_ALL_ACCESS,
                            NULL,
                            &vbKey,
                            &disp);
	}
  if( regVbaPath != NULL ) {
	  delete regVbaPath;
	  regVbaPath = NULL;
  }

  // If vbam.ini exists in executable's folder, use it. Else create/use one in %appdata% folder.
  regVbaPath = new CString();
  regVbaPath->Format(MakeInstanceFilename("%s\\vbam.ini"), path);
  if( !force && !utilFileExists( regVbaPath->GetString() ) ) {
	  TCHAR appdata[MAX_PATH+1];
	  SHGetFolderPath( NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appdata );
	  regVbaPath->Format( "%s\\VBA-M", appdata );
	  SHCreateDirectoryEx( NULL, regVbaPath->GetString(), NULL );
	  regVbaPath->Append( "\\vbam.ini" );
  }
}
Example #2
0
void isidlCloseTee(ISI_DL *dl)
{
    if (dl == NULL) return;
    if (dl->tee.fp != NULL) {
        logioMsg(dl->lp, LOG_DEBUG, "tee file %s closed", dl->tee.path);
        fclose(dl->tee.fp);
        dl->tee.fp = NULL;
    }
    if (utilFileExists(dl->tee.path)) chmod(dl->tee.path, 0644);
}
Example #3
0
static BOOL MysqlLookup(DBIO *db, UINT32 *trecs)
{
static char *path = "/usr/nrts/etc/isi.cfg";
IDAFF_GLOB ffglob;

    if (utilFileExists(path)) {
        idaffReadGlobalInitFile(path, &ffglob);
    } else {
        idaffDefaultGlob(&ffglob);
    }
    *trecs = ffglob.trecs;

    return TRUE;
}
char *LoadSystems(char *home, char *defsys)
{
int i, unused;
LNKLST list;
FILE *fp;
char *name;
char buffer[80];
char path[MAXPATHLEN+1];
NRTS_FILES *file;
char *retval = NULL;

    listInit(&list);

    sprintf(path, "%s/etc/Systems", home);
    if ((fp = fopen(path, "r")) == NULL) {
        perror(path);
        exit(1);
    }

    while (utilGetLine(fp, buffer, MAXPATHLEN, '#', &unused) == 0) {
        file = nrts_files(&home, buffer);
        if (utilFileExists(file->sys)) {
            if (!listAppend(&list, buffer, strlen(buffer)+1)) {
                listDestroy(&list);
                fclose(fp);
                perror("listAppend");
                exit(1);
            }
        }
    }
    fclose(fp);

    if (!listSetArrayView(&list)) {
        perror("listSetArrayView");
        exit(1);
    }

    if (list.count < 1) {
        fprintf(stderr, "ERROR: no valid NRTS disk loops listed in %s\n", path);
        exit(1);
    }
    nsys = list.count;

    if ((Systems = (char **) malloc(nsys * sizeof(char *))) == NULL) {
        perror("malloc");
        exit(1);
    }

    for (i = 0; i < nsys; i++) {
        if ((Systems[i] = strdup((char *) list.array[i])) == NULL) {
            perror("strdup");
            exit(1);
        }
        if (defsys != NULL && strcmp(Systems[i], defsys) == 0) retval = Systems[i];
    }

    listDestroy(&list);

    return retval == NULL ? Systems[0] : retval;

}
Example #5
0
Q330_CFG *q330ReadCfg(char *name)
{
int i, status, ntoken;
FILE *fp = NULL;
Q330_CFG *cfg = NULL;
QDP_TYPE_C1_QCAL DefaultCalib = Q330_DEFAULT_CALIB;
char *token[MAX_TOKEN];
char input[MAXLINELEN];
LNKLST *addr = NULL, *detector = NULL;
static char *DefaultName = Q330_DEFAULT_CFG_PATH;

/* Locate and open the file */

    if (name == NULL) name = getenv(Q330_CFG_ENV_STRING);
    if (name == NULL) name = DefaultName;

    if (!utilFileExists(name)) return NULL;

    if ((fp = fopen(name, "r")) == NULL) return ReadCfgCleanReturn(fp, cfg, addr, NULL);

/* Create the config structure and save the name */

    if ((cfg = CreateCfg(name)) == NULL) return ReadCfgCleanReturn(fp, cfg, addr, NULL);
    cfg->calib = DefaultCalib;

/* Initialize the temp lists */

    if ((addr = listCreate()) == NULL) return ReadCfgCleanReturn(fp, cfg, addr, NULL);
    if ((detector = listCreate()) == NULL) return ReadCfgCleanReturn(fp, cfg, addr, NULL);

/* Read the contents of the file into the list */

    while ((status = utilGetLine(fp, input, MAXLINELEN, COMMENT, NULL)) == 0) {
        ntoken = utilParse(input, token, " \t", MAX_TOKEN, QUOTE);

    /* "q330" entries define Q330_ADDR structures */

        if (strcasecmp(token[0], "q330") == 0) {

            if (!AddAddr(addr, token, ntoken)) return ReadCfgCleanReturn(fp, cfg, addr, NULL);

    /* "detector" entries define Q330_ADDR structures */

        } else if (strcasecmp(token[0], "detector") == 0) {

            if (!AddDetector(detector, token, ntoken)) return ReadCfgCleanReturn(fp, cfg, addr, NULL);

    /* "calib" entries define QDP_TYPE_C1_QCAL structures */

        } else if (strcasecmp(token[0], "calib") == 0) {

            if (!AddCalib(&cfg->calib, token, ntoken)) return ReadCfgCleanReturn(fp, cfg, addr, NULL);

    /* anything else is not supported */

        } else {
            errno = EINVAL;
            return ReadCfgCleanReturn(fp, cfg, addr, NULL);
        }
    }

    if (status != 1) return ReadCfgCleanReturn(fp, cfg, addr, NULL);

/* Copy the addresses into the output structure */

    if (!listSetArrayView(addr)) return ReadCfgCleanReturn(fp, cfg, addr, NULL);

    cfg->naddr = addr->count;
    if ((cfg->addr = (Q330_ADDR *) malloc(sizeof(Q330_ADDR) * cfg->naddr)) == NULL) return ReadCfgCleanReturn(fp, cfg, addr, NULL);
    for (i = 0; i < addr->count; i++) cfg->addr[i] = *((Q330_ADDR *) addr->array[i]);

/* Copy the detectors into the output structure */

    if (!listSetArrayView(detector)) return ReadCfgCleanReturn(fp, cfg, addr, NULL);

    cfg->ndetector = detector->count;
    if ((cfg->detector = (Q330_DETECTOR *) malloc(sizeof(Q330_DETECTOR) * cfg->ndetector)) == NULL) return ReadCfgCleanReturn(fp, cfg, detector, NULL);
    for (i = 0; i < detector->count; i++) cfg->detector[i] = *((Q330_DETECTOR *) detector->array[i]);

/* All done, return the newly created structure */

    return ReadCfgCleanReturn(fp, NULL, addr, cfg);
}