Exemple #1
0
/* init_config:
 *  Sets up the configuration routines ready for use, also loading the
 *  default config file if the loaddata flag is set and no other config
 *  file is in memory.
 */
static void init_config(int loaddata)
{
#if 0
   char buf[4][1025];
   char *s;
   int i;

   if (!config_installed) {
/*      _add_exit_func(config_cleanup);*/
      config_installed = TRUE;
   }

   if ((loaddata) && (!config[0])) {
      /* look for allegro.cfg in the same directory as the program */
      strcpy(buf[0], __crt0_argv[0]);
      strlwr(buf[0]);
      *get_filename(buf[0]) = 0;
      put_backslash(buf[0]);
      strcat(buf[0], "allegro.cfg");

      /* if that fails, try sound.cfg */
      strcpy(buf[1], __crt0_argv[0]);
      strlwr(buf[1]);
      *get_filename(buf[1]) = 0;
      put_backslash(buf[1]);
      strcat(buf[1], "sound.cfg");

      /* no luck? try the ALLEGRO enviroment variable... */
      s = getenv("ALLEGRO");
      if (s) {
	 strcpy(buf[2], s);
	 strlwr(buf[2]);
	 put_backslash(buf[2]);
	 strcat(buf[2], "allegro.cfg");

	 strcpy(buf[3], s);
	 strlwr(buf[3]);
	 put_backslash(buf[3]);
	 strcat(buf[3], "sound.cfg");
      }
      else {
	 strcpy(buf[2], buf[0]);
	 strcpy(buf[3], buf[1]);
      }
      /* see which of these files actually exist */
      for (i=0; i<4; i++) {
	 if (access (buf[i], R_OK)) {
	    set_config_file(buf[i]);
	    break;
	 }
      }

      if (i >= 4)
	 set_config_file(buf[0]);
   }
#endif   
}
Exemple #2
0
// Saves the romset out to disk. Attempts to backup originals if
// a backup doesn't already exist.
BOOL SaveDriver(void)
{
	FILE * fp = NULL;
	int i = 0;
   char FullPath[100] = {0};
   
	/* try and make the back ups */
	if (!MakeBackups())
		return FALSE;

	for (i = 0; i < NumGfxRoms; i ++)
	{
      strcpy(FullPath, ROMPathFound);
      put_backslash(FullPath);
      strcat(FullPath, ROMDirName);
      put_backslash(FullPath);
      strcat(FullPath, GfxRoms[i].ROMName);

		if ((fp = fopen(FullPath, "wb")) == NULL)
		{
			/* cant open file for write */
			DisplayError("Failed to open for write");
			return FALSE;
		}
      if (GfxRoms[i].Alternate == FALSE)
      {
         if (fwrite(&GfxRomData[GfxRoms[i].LoadAddress], 1, GfxRoms[i].Size, fp)
             != GfxRoms[i].Size)
         {
            /* bad save */
            DisplayError("Failed to save");
            fclose(fp);
            return FALSE;
         }
      }
      else
      {
         long t;
         for (t = 0; t < GfxRoms[i].Size; t++)
         {
            long Address = GfxRoms[i].LoadAddress + (t * 2);
            fputc(GfxRomData[Address],fp);
         }
      }

		fclose(fp);
	}

   return TRUE;
}
Exemple #3
0
void MakeBackupPath(const char * DirName, char * Buffer, char * Filename, int AppendFilename)
{
   strcpy(Buffer, ROMPathFound); // add the full rom path
   put_backslash(Buffer);
   strcat(Buffer, ROMDirName); // now add the directory name
   put_backslash(Buffer);
   strcat(Buffer, DirName); // now add agebak/agepatch etc.
   
	/* if caller also wants filename then append that too */
	if (AppendFilename)
	{
      put_backslash(Buffer);
		strcat(Buffer, Filename);
	}
}
Exemple #4
0
int FindRomPath(char * ROMName)
{
   int Terminator = 0;
   int Pos = 0;
   char tmpFullPath[100];
   
   for (;;)
   {
      Terminator = ScanROMPath(&ROMPath[Pos]);
      if (Terminator == -1)
         return 1;

      strncpy(tmpFullPath, &ROMPath[Pos], Terminator);
      tmpFullPath[Terminator] = 0;
      put_backslash(tmpFullPath);
      strcat(tmpFullPath, ROMName);

      // found it - return success
      if (file_exists(tmpFullPath, 0, NULL) != 0)
      {
         strncpy(ROMPathFound, &ROMPath[Pos], Terminator);
         ROMPathFound[Terminator] = 0;
         return 0;
      }
         
      if (ROMPath[Pos + Terminator] == ';')
         Terminator ++;

      Pos += Terminator;
   }
}
Exemple #5
0
FILE *romfopen(char *fn, char *mode)
{
        char s[512];
        strcpy(s, pcempath);
        put_backslash(s);
        strcat(s, fn);
        return fopen(s, mode);
}
void edit_qt()                                              //this is used to set the quest template for the current quest
{
    char tpath[2048];
    char tpath2[2048];
    strcpy(temppath, header.templatepath);
    
    if(temppath[0]==0)
    {
        getcwd(temppath,2048);
        fix_filename_case(temppath);
        fix_filename_slashes(temppath);
        put_backslash(temppath);
    }
    
    bool gotname;
    gotname=getname("Load Quest Template (.zqt)","zqt",NULL,temppath,true);
    
    if(gotname)
    {
        strcpy(tpath, temppath);
        chop_path(tpath);
        getcwd(tpath2,2048);
        fix_filename_case(tpath2);
        fix_filename_slashes(tpath2);
        put_backslash(tpath2);
        
        if(!strcmp(tpath, tpath2))
        {
            strcpy(header.templatepath, get_filename(temppath));
        }
        else
        {
            strcpy(header.templatepath, temppath);
        }
        
        if(!valid_zqt(temppath))
        {
            jwin_alert("ZQuest","Invalid Quest Template",NULL,NULL,"O&K",NULL,'k',0,lfont);
            memset(header.templatepath, 0, 2048);
        }
    }
}
Exemple #7
0
/* the back ups of the originals. */
BOOL MakeBackups(void)
{
	char BackupPath[100];
   char FromPath[100];
	FILE * fp;
	int i;

	MakeBackupPath(BackupDir, BackupPath, GfxRoms[0].ROMName, 1);

	/* are the roms already backed up? (can we open one for read) */
	if ((fp = fopen(BackupPath, "rb")) != NULL)
	{
		fclose(fp);
		return TRUE;
	}

	/* at this point we need to make backups */

	/* first create directory */
	MakeBackupPath(BackupDir, BackupPath, GfxRoms[0].ROMName, 0);
	mkdir(BackupPath, S_IRUSR | S_IWUSR);

	/* back up the roms */
	for (i = 0; i < NumGfxRoms; i ++)
	{
      strcpy(FromPath, ROMPathFound);
      put_backslash(FromPath);
      strcat(FromPath, ROMDirName);
      put_backslash(FromPath);
      strcat(FromPath, GfxRoms[i].ROMName);

		MakeBackupPath(BackupDir, BackupPath, GfxRoms[i].ROMName, 1);
		if (CopyROM(FromPath, BackupPath, GfxRoms[i].Size, 0) == FALSE)
			return FALSE;
	}

	return TRUE;
}
/* be_sys_find_resource:
 *  This is the same of the unix resource finder; it looks into the
 *  home directory and in /etc.
 */
int be_sys_find_resource(char *dest, AL_CONST char *resource, int size)
{
    char buf[256], tmp[256], *last;
    char *home = getenv("HOME");

    if (home) {
        /* look for ~/file */
        append_filename(buf, uconvert_ascii(home, tmp), resource, sizeof(buf));
        if (exists(buf)) {
            ustrzcpy(dest, size, buf);
            return 0;
        }

        /* if it is a .cfg, look for ~/.filerc */
        if (ustricmp(get_extension(resource), uconvert_ascii("cfg", tmp)) == 0) {
            ustrzcpy(buf, sizeof(buf) - ucwidth(OTHER_PATH_SEPARATOR), uconvert_ascii(home, tmp));
            put_backslash(buf);
            ustrzcat(buf, sizeof(buf), uconvert_ascii(".", tmp));
            ustrzcpy(tmp, sizeof(tmp), resource);
            ustrzcat(buf, sizeof(buf), ustrtok_r(tmp, ".", &last));
            ustrzcat(buf, sizeof(buf), uconvert_ascii("rc", tmp));
            if (file_exists(buf, FA_ARCH | FA_RDONLY | FA_HIDDEN, NULL)) {
                ustrzcpy(dest, size, buf);
                return 0;
            }
        }
    }

    /* look for /etc/file */
    append_filename(buf, uconvert_ascii("/etc/", tmp), resource, sizeof(buf));
    if (exists(buf)) {
        ustrzcpy(dest, size, buf);
        return 0;
    }

    /* if it is a .cfg, look for /etc/filerc */
    if (ustricmp(get_extension(resource), uconvert_ascii("cfg", tmp)) == 0) {
        ustrzcpy(buf, sizeof(buf), uconvert_ascii("/etc/", tmp));
        ustrzcpy(tmp, sizeof(tmp), resource);
        ustrzcat(buf, sizeof(buf), ustrtok_r(tmp, ".", &last));
        ustrzcat(buf, sizeof(buf), uconvert_ascii("rc", tmp));
        if (exists(buf)) {
            ustrzcpy(dest, size, buf);
            return 0;
        }
    }

    return -1;
}
Exemple #9
0
int rom_present(char *fn)
{
        FILE *f;
        char s[512];
        
        strcpy(s, pcempath);
        put_backslash(s);
        strcat(s, fn);
        f = fopen(s, "rb");
        if (f)
        {
                fclose(f);
                return 1;
        }
        return 0;
}
Exemple #10
0
bool validate_user_file_path(const char *fnmm, char *output, bool currentDirOnly)
{
  if (strncmp(fnmm, "$SAVEGAMEDIR$", 13) == 0) 
  {
    fnmm += 14;
    sprintf(output, "%s%s", saveGameDirectory, fnmm);
  }
  else if (strncmp(fnmm, "$APPDATADIR$", 12) == 0) 
  {
    fnmm += 13;
    const char *appDataDir = platform->GetAllUsersDataDirectory();
    if (appDataDir == NULL) appDataDir = ".";
    if (game.saveGameFolderName[0] != 0)
    {
      sprintf(output, "%s/%s", appDataDir, game.saveGameFolderName);
      fix_filename_slashes(output);
      mkdir(output);
    }
    else 
    {
      strcpy(output, appDataDir);
    }
    put_backslash(output);
    strcat(output, fnmm);
  }
  else
  {
    get_current_dir_path(output, fnmm);
  }

  // don't allow access to files outside current dir
  if (!currentDirOnly) { }
  else if ((strchr (fnmm, '/') != NULL) || (strchr(fnmm, '\\') != NULL) ||
    (strstr(fnmm, "..") != NULL) || (strchr(fnmm, ':') != NULL)) {
    debug_log("Attempt to access file '%s' denied (not current directory)", fnmm);
    return false;
  }

  return true;
}
Exemple #11
0
BOOL LoadGfxRomData(void)
{
   int i;
   FILE * fp;
   char ROMDirWithName[50];
   int total = 0;

   // find the rom path. Use the first rom name from the set
   sprintf(ROMDirWithName, "%s/%s", ROMDirName, GfxRoms[0].ROMName);
   if (FindRomPath(ROMDirWithName) != 0)
   {
      DisplayError("%s not found", GfxRoms[0].ROMName);
      return FALSE;
   }
   
   // allocate the memory to store the roms
   for (i = 0; i < NumGfxRoms; i ++)
      total += GfxRoms[i].Size;

   GfxRomData = malloc(total);
   if (GfxRomData == NULL)
   {
      DisplayError("GfxRomData malloc failed");
      return FALSE;
   }
   
   for (i = 0; i < NumGfxRoms; i ++)
   {
      char FullPath[120];

      // build full path including filename
      strcpy(FullPath, ROMPathFound);
      put_backslash(FullPath);
      strcat(FullPath, ROMDirName);
      put_backslash(FullPath);
      strcat(FullPath, GfxRoms[i].ROMName);

      if ((fp = fopen(FullPath, "rb")) == NULL)
      {
         /* file not found */
         free(GfxRomData);
         DisplayError("File not found");
         return FALSE;
      }

      if (GfxRoms[i].Alternate == FALSE)
      {
         if (fread(&GfxRomData[GfxRoms[i].LoadAddress], 1,
                   GfxRoms[i].Size, fp) != GfxRoms[i].Size)
         {
            /* bad load */
            free(GfxRomData);
            DisplayError("ROM Size load error");
            fclose(fp);
            return FALSE;
         }
      }
      else
      {
         long t;
         for (t = 0; t < GfxRoms[i].Size; t++)
         {
            long Address = GfxRoms[i].LoadAddress + (t * 2);
            GfxRomData[Address] = fgetc(fp);
         }
      }


      fclose(fp);
   }
   
   return TRUE;
}
/* fs_flist_putter:
  *  Callback routine for for_each_file() to fill the file selector listbox.
  */
static int fs_flist_putter(AL_CONST char *str, int attrib, void *check_attrib)
{
    char *s, *ext, *name;
    int c, c2;
    
    s = get_filename(str);
    fix_filename_case(s);
    
    if(!(attrib & FA_DIREC))
    {
        /* Check if file extension matches. */
        if(fext_p)
        {
            ext = get_extension(s);
            
            for(c=0; c<fext_size; c++)
            {
                if(ustricmp(ext, fext_p[c]) == 0)
                    goto Next;
            }
            
            return 0;
        }
        
Next:

        /* Check if file attributes match. */
        if(check_attrib)
        {
            for(c=0; c<ATTRB_MAX; c++)
            {
                if((attrb_state[c] == ATTRB_SET) && (!(attrib & attrb_flag[c])))
                    return 0;
                    
                if((attrb_state[c] == ATTRB_UNSET) && (attrib & attrb_flag[c]))
                    return 0;
            }
        }
    }
    
    if((flist->size < FLIST_SIZE) && ((ugetc(s) != '.') || (ugetat(s, 1))))
    {
        int size = ustrsizez(s) + ((attrib & FA_DIREC) ? ucwidth(OTHER_PATH_SEPARATOR) : 0);
        name = (char *) zc_malloc(size);
        
        if(!name)
            return -1;
            
        ustrzcpy(name, size, s);
        
        if(attrib & FA_DIREC)
            put_backslash(name);
            
        /* Sort alphabetically with directories first. */
        for(c=0; c<flist->size; c++)
        {
            if(ugetat(flist->name[c], -1) == OTHER_PATH_SEPARATOR)
            {
                if(attrib & FA_DIREC)
                    if(ustrfilecmp(name, flist->name[c]) < 0)
                        break;
            }
            else
            {
                if(attrib & FA_DIREC)
                    break;
                    
                if(ustrfilecmp(name, flist->name[c]) < 0)
                    break;
            }
        }
        
        /* Shift in preparation for inserting the new entry. */
        for(c2=flist->size; c2>c; c2--)
            flist->name[c2] = flist->name[c2-1];
            
        /* Insert the new entry. */
        flist->name[c] = name;
        flist->size++;
    }
    
    return 0;
}
Exemple #13
0
const FileItemList& FileItem::getChildren()
{
  // Is the file-item a folder?
  if (IS_FOLDER(this) &&
      // if the children list is empty, or the file-system version
      // change (it's like to say: the current this->children list
      // is outdated)...
      (this->children.empty() ||
       current_file_system_version > this->version)) {
    FileItemList::iterator it;
    FileItem* child;

    // we have to mark current items as deprecated
    for (it=this->children.begin();
         it!=this->children.end(); ++it) {
      child = static_cast<FileItem*>(*it);
      child->removed = true;
    }

    //PRINTF("FS: Loading files for %p (%s)\n", fileitem, fileitem->displayname);
#ifdef USE_PIDLS
    {
      IShellFolder* pFolder = NULL;

      if (this == rootitem)
        pFolder = shl_idesktop;
      else
        shl_idesktop->BindToObject(this->fullpidl,
                                   NULL,
                                   IID_IShellFolder,
                                   (LPVOID *)&pFolder);

      if (pFolder != NULL) {
        IEnumIDList *pEnum = NULL;
        ULONG c, fetched;

        /* get the interface to enumerate subitems */
        pFolder->EnumObjects(win_get_window(),
                             SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &pEnum);

        if (pEnum != NULL) {
          LPITEMIDLIST itempidl[256];
          SFGAOF attribs[256];

          /* enumerate the items in the folder */
          while (pEnum->Next(256, itempidl, &fetched) == S_OK && fetched > 0) {
            /* request the SFGAO_FOLDER attribute to know what of the
               item is a folder */
            for (c=0; c<fetched; ++c) {
              attribs[c] = SFGAO_FOLDER;
              pFolder->GetAttributesOf(1, (LPCITEMIDLIST *)itempidl, attribs+c);
            }

            /* generate the FileItems */
            for (c=0; c<fetched; ++c) {
              LPITEMIDLIST fullpidl = concat_pidl(this->fullpidl,
                                                  itempidl[c]);

              child = get_fileitem_by_fullpidl(fullpidl, false);
              if (!child) {
                child = new FileItem(this);

                child->pidl = itempidl[c];
                child->fullpidl = fullpidl;
                child->attrib = attribs[c];

                update_by_pidl(child);
                put_fileitem(child);
              }
              else {
                ASSERT(child->parent == this);
                free_pidl(fullpidl);
                free_pidl(itempidl[c]);
              }

              this->insertChildSorted(child);
            }
          }

          pEnum->Release();
        }

        if (pFolder != shl_idesktop)
          pFolder->Release();
      }
    }
#else
    {
      char buf[MAX_PATH], path[MAX_PATH], tmp[32];

      ustrcpy(path, this->filename.c_str());
      put_backslash(path);

      replace_filename(buf,
                       path,
                       uconvert_ascii("*.*", tmp),
                       sizeof(buf));

#ifdef WORKAROUND_64BITS_SUPPORT
      // we cannot use the for_each_file's 'param' to wrap a 64-bits pointer
      for_each_child_callback_param = this;
      for_each_file(buf, FA_TO_SHOW, for_each_child_callback, 0);
#else
      for_each_file(buf, FA_TO_SHOW,
                    for_each_child_callback,
                    (int)this);
#endif
  }
#endif

    // check old file-items (maybe removed directories or file-items)
    for (it=this->children.begin();
         it!=this->children.end(); ) {
      child = static_cast<FileItem*>(*it);
      if (child->removed) {
        it = this->children.erase(it);

        fileitems_map->erase(fileitems_map->find(child->keyname));
        delete child;
      }
      else
        ++it;
    }

    // now this file-item is updated
    this->version = current_file_system_version;
  }

  return this->children;
}
void edit_qt(int index)
{
    int ret;
    quest_template tqt;
    char tpath[2048];
    char tpath2[2048];
    tqt=QuestTemplates[index];
    editqt_dlg[0].dp2=lfont;
    
    do
    {
        editqt_dlg[6].dp=QuestTemplates[index].name;
        editqt_dlg[8].dp=QuestTemplates[index].path;
        strcpy(temppath, QuestTemplates[index].path);
        bool gotname;
        
        if(is_large)
            large_dialog(editqt_dlg);
            
        ret=zc_popup_dialog(editqt_dlg,6);
        
        switch(ret)
        {
        case 2:
            gotname=getname("Load Quest Template (.zqt)","zqt",NULL,temppath,true);
            
            if(gotname)
            {
                strcpy(tpath, temppath);
                chop_path(tpath);
                getcwd(tpath2,2048);
                fix_filename_case(tpath2);
                fix_filename_slashes(tpath2);
                put_backslash(tpath2);
                
                if(!strcmp(tpath, tpath2))
                {
                    strcpy(QuestTemplates[index].path, get_filename(temppath));
                }
                else
                {
                    strcpy(QuestTemplates[index].path, temppath);
                }
            }
            
            break;
            
        case 3:
        
            if(!valid_zqt(temppath))
            {
                ret=2;
                jwin_alert("ZQuest","Invalid Quest Template",NULL,NULL,"O&K",NULL,'k',0,lfont);
                break;
            }
            
            if(index==qt_count)
            {
                ++qt_count;
            }
            
            break;
            
        case 4:
            QuestTemplates[index]=tqt;
            break;
        }
    }
    while(ret==2);
}
Exemple #15
0
void get_args(int argc, char *argv[])
{
	int i;
	char temp[50];
	char temp2[50];

	for(i=1;i<argc;i++)
		if(argv[i][0] == '-' || argv[i][0] == '/')
		{
			strncpy(temp, argv[i]+1, strlen(argv[i]));
						
			if(strcasecmp(temp,"debug")==0)
			{
				debug_is_on =1;
			}
			else if(strcasecmp(temp,"vsync")==0)
			{
				vsync_is_on =1;
			}
			else if(strcasecmp(temp,"nosound")==0)
			{
				sound_is_on =0;
			}
			else if(strcasecmp(temp,"sounddriver")==0)
			{
				if(i+1<argc)
				{
					fiend_sound_driver = atoi(argv[i+1]);
					i++;
				}
			}
			else if(strcasecmp(temp,"sounddriver")==0)
			{
				if(i+1<argc)
				{
					fiend_gfx_driver = atoi(argv[i+1]);
					i++;
				}
			}
			else if(strcasecmp(temp,"map")==0)
			{
				if(i+1<argc)
				{
					strcpy(map_file,argv[i+1]);
					i++;
				}
			}
			else if(strcasecmp(temp,"mapdata")==0)
			{
				if(i+1<argc)
				{
					strcpy(temp2,argv[i+1]);
					
					put_backslash(temp2);

					sprintf(global_var_filename, "%svars.inf",temp2);
					sprintf(global_trigger_filename, "%striggers.inf",temp2);
					sprintf(npc_filename, "%snpc.inf",temp2);
					sprintf(item_filename, "%sitem.inf",temp2);
					sprintf(enemy_filename, "%senemy.inf",temp2);

					fiend_show_intro = 0;
										
					i++;
				}
			}

		}
}
Exemple #16
0
void DoComparison(char * ROMName, long Size)
{
	char BackupPath[100] = {0};
	char PatchPath[100] = {0};
   char FullPath[100] = {0};
	FILE * fpModifiedRom = NULL;
	FILE * fpBackupRom = NULL;
	FILE * fpPatchRom = NULL;
	long StartSeq = -1, SeqLen = 0, j;
	int HeaderWritten = 0;

	/* open the backup ROM (do this first as it is the most likely to fail) */
	MakeBackupPath(BackupDir, BackupPath, ROMName, 1);
	if ((fpBackupRom = fopen(BackupPath, "rb")) == NULL)
	{
		/* just be quiet about this as it only means that the user hasn't edited */
		/* either the maps or the graphics therefore there is no backup for them */
		/* and no patch needed anyway */
		return;
	}

	/* now open the modified rom */
   strcpy(FullPath, ROMPathFound);
   put_backslash(FullPath);
   strcat(FullPath, ROMDirName);
   put_backslash(FullPath);
   strcat(FullPath, ROMName);

	if ((fpModifiedRom = fopen(FullPath, "rb")) == NULL)
	{
		printf("ERROR: Failed to open modified rom \"%s\"\n skipping", ROMName);
		fclose(fpBackupRom);
		return;
	}

	/* on to the comparison and creating the IPS file */
	/* Compare Roms */
	StartSeq = -1;

	for (j = 0; j < Size; j ++)
	{
		BYTE BackupCh = fgetc(fpBackupRom);
		BYTE ModifiedCh = fgetc(fpModifiedRom);

		/* do bytes match? */
		if (BackupCh != ModifiedCh)
		{
			/* set up our start flag if it is not already done */
			if (StartSeq == -1)
			{
				StartSeq = j;
				SeqLen = 0;
				if (!HeaderWritten)
				{
					/* create patch file */
					MakeBackupPath(PatchDir, PatchPath,ROMName, 1);
					if ((fpPatchRom = fopen(PatchPath, "wb")) == NULL)
					{
						/* cant open file for write */
						printf("ERROR: Failed to create patch file: \"%s\" skipping\n", PatchPath);
						fclose(fpBackupRom);
						fclose(fpModifiedRom);
						return;
					}

					fwrite("PATCH", 1, 5, fpPatchRom);
					HeaderWritten = 1;
				}
			}

			SeqLen ++;
			/* don't allow to overflow 2 bytes */
			if (SeqLen == 65535)
			{
				WritePatchChanges(StartSeq, SeqLen, fpModifiedRom, fpPatchRom);
				StartSeq = -1;
				SeqLen = 0;
			}
		}
		else
		{
			/* bytes match - do we need to write any patch file */
			if (StartSeq != -1)
			{
				WritePatchChanges(StartSeq, SeqLen, fpModifiedRom, fpPatchRom);
				StartSeq = -1;
				SeqLen = 0;
			}
		}
	}

	/* do we need to write trailer? */
	if (HeaderWritten)
	{
		/* have we written all of the changes */
		if (StartSeq != -1)
		{
			WritePatchChanges(StartSeq, SeqLen, fpModifiedRom, fpPatchRom);
			StartSeq = -1;
			SeqLen = 0;
		}
		fwrite("EOF", 1, 3, fpPatchRom);
		HeaderWritten = 0;
		fclose(fpPatchRom);
	}

	fclose(fpBackupRom);
}
Exemple #17
0
/* fs_edit_proc:
 *  Dialog procedure for the file selector editable string.
 */
static int fs_edit_proc(int msg, DIALOG *d, int c)
{
   char *s = d->dp;
   int list_size;
   int found = 0;
   char b[512];
   int ch, attr;
   int i;

   if (msg == MSG_START) {
      fix_filename_path(b, s, sizeof(b));
      ustrcpy(s, b);
   }

   if (msg == MSG_KEY) {
      if ((!ugetc(s)) || (ugetat(s, -1) == DEVICE_SEPARATOR))
	 ustrcat(s, uconvert_ascii("./", NULL));

      fix_filename_path(b, s, sizeof(b));
      ustrcpy(s, b);

      ch = ugetat(s, -1);
      if ((ch != '/') && (ch != OTHER_PATH_SEPARATOR)) {
	 if (file_exists(s, FA_RDONLY | FA_HIDDEN | FA_DIREC, &attr)) {
	    if (attr & FA_DIREC)
	       put_backslash(s);
	    else
	       return D_CLOSE;
	 }
	 else
	    return D_CLOSE;
      }

      scare_mouse();
      SEND_MESSAGE(file_selector+FS_FILES, MSG_START, 0);
      /* did we `cd ..' ? */
      if (ustrlen(updir)) {
	 /* now we have to find a directory name equal to updir */
	 for (i = 0; i<flist->size; i++) {
	    if (!ustrcmp(updir, flist->name[i])) {  /* we got it ! */
	       file_selector[FS_FILES].d1 = i;
	       /* we have to know the number of visible lines in the filelist */
	       /* -1 to avoid an off-by-one problem */
               list_size = (file_selector[FS_FILES].h-4) / text_height(font) - 1;
               if (i>list_size)
		  file_selector[FS_FILES].d2 = i-list_size;
	       else
		  file_selector[FS_FILES].d2 = 0;
               found = 1;
	       break;  /* ok, our work is done... */
	    }
	 }
	 /* by some strange reason, we didn't find the old directory... */
         if (!found) {
            file_selector[FS_FILES].d1 = 0;
            file_selector[FS_FILES].d2 = 0;
         }
      }
      /* and continue... */
      SEND_MESSAGE(file_selector+FS_FILES, MSG_DRAW, 0);
      SEND_MESSAGE(d, MSG_START, 0);
      SEND_MESSAGE(d, MSG_DRAW, 0);
      unscare_mouse();

      return D_O_K;
   }

   if (msg == MSG_UCHAR) {
      if ((c >= 'a') && (c <= 'z')) {
	 if (!ALLEGRO_LFN)
	    c = utoupper(c);
      }
      else if (c == '/') {
	 c = OTHER_PATH_SEPARATOR;
      }
      else if (ALLEGRO_LFN) {
	 if ((c > 127) || (c < 32))
	    return D_O_K;
      }
      else {
	 if ((c != OTHER_PATH_SEPARATOR) && (c != '_') &&
	     (c != DEVICE_SEPARATOR) && (c != '.') &&
	     ((c < 'A') || (c > 'Z')) && ((c < '0') || (c > '9')))
	    return D_O_K;
      }
   }

   return x_edit_proc(msg, d, c);
}
/* fs_edit_proc:
  *  Dialog procedure for the file selector editable string.
  */
static int fs_edit_proc(int msg, DIALOG *d, int c)
{
    char *s = (char *) d->dp;
    int size = (d->d1 + 1) * uwidth_max(U_CURRENT);           /* of s (in bytes) */
    int list_size;
    int found = 0;
    char b[1024], tmp[16];
    int ch, attr;
    int i;
    
    if(msg == MSG_START)
    {
        canonicalize_filename(b, s, sizeof(b));
        ustrzcpy(s, size, b);
    }
    
    if(msg == MSG_KEY)
    {
        if((!ugetc(s)) || (ugetat(s, -1) == DEVICE_SEPARATOR))
            ustrzcat(s, size, uconvert_ascii("./", tmp));
            
        canonicalize_filename(b, s, sizeof(b));
        ustrzcpy(s, size - ucwidth(OTHER_PATH_SEPARATOR), b);
        
        ch = ugetat(s, -1);
        
        if((ch != '/') && (ch != OTHER_PATH_SEPARATOR))
        {
            if(file_exists(s, FA_RDONLY | FA_HIDDEN | FA_DIREC, &attr))
            {
                if(attr & FA_DIREC)
                    put_backslash(s);
                else
                    return D_CLOSE;
            }
            else
                return D_CLOSE;
        }
        
        object_message(file_selector+FS_FILES, MSG_START, 0);
        
        /* did we `cd ..' ? */
        if(ustrlen(updir))
        {
            /* now we have to find a directory name equal to updir */
            for(i = 0; i<flist->size; i++)
            {
                if(!ustrcmp(updir, flist->name[i]))                 /* we got it ! */
                {
                    file_selector[FS_FILES].d1 = i;
                    /* we have to know the number of visible lines in the filelist */
                    /* -1 to avoid an off-by-one problem */
                    list_size = (file_selector[FS_FILES].h-4) / text_height(font) - 1;
                    
                    if(i>list_size)
                        file_selector[FS_FILES].d2 = i-list_size;
                    else
                        file_selector[FS_FILES].d2 = 0;
                        
                    found = 1;
                    break;                                            /* ok, our work is done... */
                }
            }
            
            /* by some strange reason, we didn't find the old directory... */
            if(!found)
            {
                file_selector[FS_FILES].d1 = 0;
                file_selector[FS_FILES].d2 = 0;
            }
        }
        
        /* and continue... */
        object_message(file_selector+FS_FILES, MSG_DRAW, 0);
        object_message(d, MSG_START, 0);
        object_message(d, MSG_DRAW, 0);
        
        return D_O_K;
    }
    
    int allegro_lfn = ALLEGRO_LFN; //removes compiler warning
    
    if(msg == MSG_UCHAR)
    {
        if((c >= 'a') && (c <= 'z'))
        {
            if(!allegro_lfn)
                c = utoupper(c);
        }
        else if(c == '/')
        {
            c = OTHER_PATH_SEPARATOR;
        }
        else if(allegro_lfn)
        {
            if((c > 127) || (c < 32))
                return D_O_K;
        }
        else
        {
            if((c != OTHER_PATH_SEPARATOR) && (c != '_') &&
                    (c != DEVICE_SEPARATOR) && (c != '.') &&
                    ((c < 'A') || (c > 'Z')) && ((c < '0') || (c > '9')))
                return D_O_K;
        }
    }
    
    //   return _gui_edit_proc(msg, d, c);
    return jwin_edit_proc(msg, d, c);
}
Exemple #19
0
/* fs_flist_putter:
 *  Callback routine for for_each_file() to fill the file selector listbox.
 */
static void fs_flist_putter(AL_CONST char *str, int attrib, int param)
{
   char ext_tokens[32];
   char *s, *ext, *tok, *name;
   char tmp[512], tmp2[32];
   int c, c2, i, k, sign;

   /* attribute flags (rhsda order)
    * 0 = not required, 1 = must be set, -1 = must be unset
    */
   int attr_flag[5+5] = {
      0, -1, -1, 0, 0,
      FA_RDONLY, FA_HIDDEN, FA_SYSTEM, FA_DIREC, FA_ARCH
   };

   c = usetc(ext_tokens, ' ');
   c += usetc(ext_tokens+c, ',');
   c += usetc(ext_tokens+c, ';');
   usetc(ext_tokens+c, 0);

   s = get_filename(str);
   fix_filename_case(s);

   if (fext) {
      ustrcpy(tmp, fext);
      ustrtok(tmp, ext_tokens);
      c = (ustrtok(NULL, ext_tokens) ? 1 : 0);
      if (!c) {
	 if (!ustrchr(fext, '/'))
	    c = 1;
      }

      if (c && (!(attrib & FA_DIREC))) {
	 ustrcpy(tmp, fext);
	 ext = get_extension(s);
	 tok = ustrtok(tmp, ext_tokens);

	 while (tok) {
	    if (ustricmp(ext, tok) == 0)
	       break;

	    tok = ustrtok(NULL, ext_tokens);
	 }

	 if (!tok)
	    return;
      }

      c = usetc(ext_tokens, ' ');
      c += usetc(ext_tokens+c, ',');
      c += usetc(ext_tokens+c, ';');
      c += usetc(ext_tokens+c, '/');
      usetc(ext_tokens+c, 0);

      ustrcpy(tmp, fext);
      tok = ustrchr(tmp, '/');

      if (tok)
	 tok = ustrtok(tok, ext_tokens);

      if (tok) {
	 sign = 1;
	 c = usetc(tmp2, 'r');
	 c += usetc(tmp2+c, 'h');
	 c += usetc(tmp2+c, 's');
	 c += usetc(tmp2+c, 'd');
	 c += usetc(tmp2+c, 'a');
	 c += usetc(tmp2+c, '+');
	 c += usetc(tmp2+c, '-');
	 usetc(tmp2+c, 0);

	 /* scan the string */
	 i = 0;
	 while ((c = utolower(ugetat(tok, i)))) {
	    k = 0;
	    while ((c2 = ugetat(tmp2, k))!=0) {
	       if (c == c2) {
		  if (k<5) {
		     attr_flag[k] = sign;
		     break;
		  }
		  else
		     sign = (k==5) ? 1 : -1;
	       }
	       k++;
	    }
	    i++;
	 }
      }
   }

   /* check if file attributes match */
   if (!(attr_flag[3+5] & attrib)) {
      /* if not a directory, we check all attributes except FA_DIREC */
      for (c=0; c<5; c++) {
	 if (c == 3)
	    continue;
	 if ((attr_flag[c] == 1) && (!(attrib & attr_flag[c+5])))
	    return;
	 if ((attr_flag[c] == -1) && (attrib & attr_flag[c+5]))
	    return;
      }
   }
   else {
      /* if a directory, we check only FA_DIREC */
      if (attr_flag[3] == -1)
	 return;
   }

   if ((flist->size < FLIST_SIZE) && ((ugetc(s) != '.') || (ugetat(s, 1)))) {
      name = malloc(ustrsizez(s) + ((attrib & FA_DIREC) ? ucwidth(OTHER_PATH_SEPARATOR) : 0));
      if (!name)
	 return;

      for (c=0; c<flist->size; c++) {
	 if (ugetat(flist->name[c], -1) == OTHER_PATH_SEPARATOR) {
	    if (attrib & FA_DIREC)
	       if (ustrfilecmp(s, flist->name[c]) < 0)
		  break;
	 }
	 else {
	    if (attrib & FA_DIREC)
	       break;
	    if (ustrfilecmp(s, flist->name[c]) < 0)
	       break;
	 }
      }

      for (c2=flist->size; c2>c; c2--)
	 flist->name[c2] = flist->name[c2-1];

      flist->name[c] = name;
      ustrcpy(flist->name[c], s);

      if (attrib & FA_DIREC)
	 put_backslash(flist->name[c]);

      flist->size++;
   }
}
/* jwin_file_select_ex:
  *  Displays the JWin file selector, with the message as caption.
  *  Allows the user to select a file, and stores the selection in the
  *  path buffer, whose length in bytes is given by size and should have
  *  room for at least 80 characters. The files are filtered according to
  *  the file extensions in ext. Passing NULL includes all files, "PCX;BMP"
  *  includes only files with .PCX or .BMP extensions. Returns zero if it
  *  was closed with the Cancel button or non-zero if it was OK'd.
  */
int jwin_file_select_ex(AL_CONST char *message, char *path, AL_CONST char *ext, int size, int width, int height, FONT *title_font)
{
    static attrb_state_t default_attrb_state[ATTRB_MAX] = DEFAULT_ATTRB_STATE;
    int ret;
    char *p;
    char tmp[32];
    ASSERT(message);
    ASSERT(path);
    
    if(title_font)
    {
        file_selector[0].dp2=title_font;
    }
    
    if(width == OLD_FILESEL_WIDTH)
        width = 304;
        
#ifdef HAVE_DIR_LIST
        
    if(height == OLD_FILESEL_HEIGHT)
        height = 160;
        
#else
        
    if(height == OLD_FILESEL_HEIGHT)
        height = 188;
        
#endif
        
    /* for fs_dlist_proc() */
    ASSERT(size >= 4 * uwidth_max(U_CURRENT));
    
    usetc(updir, 0);
    file_selector[FS_WIN].dp = (char *)message;
    file_selector[FS_EDIT].d1 = size/uwidth_max(U_CURRENT) - 1;
    file_selector[FS_EDIT].dp = path;
    file_selector[FS_OK].dp = (void*)get_config_text("OK");
    file_selector[FS_CANCEL].dp = (void*)get_config_text("Cancel");
    
    /* Set default attributes. */
    memcpy(attrb_state, default_attrb_state, sizeof(default_attrb_state));
    
    /* Parse extension string. */
//  if (ext)// && ugetc(ext))
    {
        parse_extension_string(ext);
    }
    
    if(!ugetc(path))
    {
    
#ifdef HAVE_DIR_LIST
    
        int drive = _al_getdrive();
        
#else
        
        int drive = 0;
#endif
        
        _al_getdcwd(drive, path, size - ucwidth(OTHER_PATH_SEPARATOR));
        fix_filename_case(path);
        fix_filename_slashes(path);
        put_backslash(path);
    }
    
    clear_keybuf();
    
    do
    {
    }
    while(gui_mouse_b());
    
    file_selector[FS_TYPES].proc = fs_dummy_proc;
    enlarge_file_selector(width, height);
    ret = popup_zqdialog(file_selector, FS_EDIT);
    
    if(fext)
    {
        zc_free(fext);
        fext = NULL;
    }
    
    if(fext_p)
    {
        _al_free(fext_p);
        fext_p = NULL;
    }
    
    if((ret == FS_CANCEL) || (ret == FS_WIN) || (!ugetc(get_filename(path))))
        return FALSE;
        
    p = get_extension(path);
    
    if((!ugetc(p)) && (ext) && (!ustrpbrk(ext, uconvert_ascii(" ,;", tmp))))
    {
        size -= ((long)(size_t)p - (long)(size_t)path + ucwidth('.'));
        
        if(size >= uwidth_max(U_CURRENT) + ucwidth(0))          /* do not end with '.' */
        {
            p += usetc(p, '.');
            ustrzcpy(p, size, ext);
        }
    }
    
    return TRUE;
}
Exemple #21
0
int raine_file_select_ex( char *message, char *path,  char *ext, int size,int width, int height)
{
   char buf[512];
   int ret;
   char *p;

   if (width == -1)
      width = 305;

   #ifdef HAVE_DIR_LIST

      if (height == -1)
         height = 161;

   #else

      if (height == -1)
         height = 189;

   #endif

   /* for fs_dlist_proc() */
   ASSERT(size >= 4 * uwidth_max(U_CURRENT));

   ustrcpy(updir, empty_string);
   file_selector[FS_MESSAGE].dp = (char *)message;
   file_selector[FS_EDIT].d1 = size/uwidth_max(U_CURRENT) - 1;
   file_selector[FS_EDIT].dp = path;
   file_selector[FS_OK].dp = (void*)raine_get_config_text("OK");
   file_selector[FS_CANCEL].dp = (void*)raine_get_config_text("Cancel");
   fext = ext;

   if (!ugetc(path)) {
      if (!getcwd(buf, sizeof(buf)))
         buf[0]=0;
      do_uconvert(buf, U_ASCII, path, U_CURRENT, size);
      fix_filename_case(path);
      fix_filename_slashes(path);
      put_backslash(path);
   }

   clear_keybuf();

   do {
   } while (gui_mouse_b());

   stretch_dialog(file_selector, width, height);

   centre_dialog(file_selector);
   // Stupid correction of the allegro colors...
   file_selector[FS_FILES].fg = CGUI_COL_TEXT_1;
   file_selector[FS_FILES].bg = CGUI_BOX_COL_MIDDLE;
#ifdef HAVE_DIR_LIST       /* not all platforms need a directory list */
   file_selector[FS_DISKS].fg = CGUI_COL_TEXT_1;
   file_selector[FS_DISKS].bg = CGUI_BOX_COL_MIDDLE;
#endif

   ret = do_dialog(file_selector, FS_EDIT);

   if (ret == FS_CANCEL)
      return FALSE;

   p = get_extension(path);
   if ((!ugetc(p)) && (ext) && (!ustrpbrk(ext, uconvert_ascii(" ,;", NULL)))) {
      p += usetc(p, '.');
      ustrcpy(p, ext);
   }

   return TRUE;
}