[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Some Ridiculous Newbie Questions re Mac::Files, etc.



Hi all,

Excuse the newbie questions, but I've read the MacPerl list in the past
and found it extraordinarily helpful. I mainly use Perl in a Unix
environment, but I'm a big devotee of MacMAME (the Mac port of MAME, a
freeware program for emulating old arcade games; http://www.macmame.org).

I was looking for a utility to tell me which MacMAME ROMsets (the files
for the individual games) I was missing from the complete list (which now
numbers nearly 1700). Not finding one, I wrote myself a command-line one,
which reads in the contents of the MacMAME "Roms" directory, and compares
it against a list generated by the program, generally called "MAME Game
List". It then reads to STDOUT and creates a dump textfile.

After writing one (with file locations,etc. hard-coded in), I thought that
it might be useful to strap some friendly UI elements on it and distribute
it for others. I ran into the roadblock of the fact that even though my
home machine is a Mac, I was woefully ignorant of the basics of MacPerl
Toolbox usage. I consulted MP:PE, but was unable to find quickly what I
was looking for.

Therefore, I'm looking for the answers to three (probably simply and
easily RTFM'ed) questions:

1.) How can I get a MacOS 8.5+ (?) style dialog like one that will allow
the user to select a directory (in this case, their MacMAME base
directory), so the contents of a directory relative to that directory can
be opened and read?

2.) For the above, as well as the dialog in which they select their "MAME
Game List," is there an easy way to print a simple message in the dialog
box (e.g., "Select your MacMAME Directory:" and "Select your MAME Game
List File:")?

3. After the work is done, is there an easy way to set the file's
type/creator codes to "TEXT/ttxt" rather than the default MPW document?

Thanks in advance. I'm sure these questions are rather foolish, but I
appreciate your patience with my Mac programming inadequacy. ;)

FWIW, below is the source as I have it now (mainly my CLI-based original,
with the few Mac elements I could strap on to it):

----------------------------------------------------------------------
#! /usr/bin/perl -w
# ROMsets Needed, still in moron Mac programmer alpha ;)

use Mac::StandardFile;
use Mac::Files;

## Setup
my ($ROMDir) = 'Archie II:Emulation:MacMAME:Roms';
my ($OutputFile) = 'Archie II:ROMsets Needed';

## Program
print "Select MAME ROM Info File:\n";
sleep (3);
my ($ROMList) = StandardGetFile(0,0);

if ($ROMList ->sfGood()) {
     $SupportedROMsFile = $ROMList ->sfFile();
} else {
     die ("Problem with file $SupportedROMsFile: $! $^E\n");
}

opendir(DIR, $ROMDir) || die("Couldn't find ROM directory. Error: $!
$^E\n");
my @DirCont = readdir(DIR);
closedir(DIR) || die("Filesystem error: $! $^E\n");

my %HaveRoms;
for(@DirCont) {
    s/\.zip//;			
    $HaveROMs{$_} = 1;
}

my($NumROMs, @NeedROMs) = (0);
open(FILE, $SupportedROMsFile) || die("Couldn't open supported ROMsets
list: $! $^E");
while(<FILE>) {
	   if(/\s*(\S+)\s+"([^"]*)"\s*$/) {
        unless($HaveROMs{$1}) { push(@NeedROMs, sprintf("%-10s - %s", $1,
$2)); }
	       $NumROMs++;
    }
}
close(FILE);

open (OUTPUTFILE, ">$OutputFile") || warn ("Couldn't create output file:
$! $^E\n");

print "I need the following ROMs:\n\n";
for(@NeedROMs) { 
     print"$_\n"; 
     print OUTPUTFILE "$_\n";
}

my $MyNumROMs = int keys %HaveROMs;
my $NumNeed   = $NumROMs - $MyNumROMs;

print "\n\nNumber of ROMs:       $MyNumROMs\n";
print "Number of Total ROMsets Supported: $NumROMs\n";
print "$NumNeed ROMsets Needed.\n";
print "\nDone.\n";

print OUTPUTFILE "Displaying Needed MacMAME ROMsets.\n\n";
print OUTPUTFILE "\n\nNumber of ROMs:       $MyNumROMs\n";
print OUTPUTFILE "Number of Total ROMsets Supported: $NumROMs\n";
print OUTPUTFILE "$NumNeed ROMsets Needed.\n";

close (OUTPUTFILE);

----------------------------------------------------------------------

---------------------------------
Jeffrey Carl	Chief M*rketing Weasel, ServInt Internet Services
(703) 847-1381 voice			(703) 847-1383 fax
"Another journalism major enters the workforce..." -Dilbert
---------------------------------


# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org