Permalink
Browse files

Store DOSBox captures on the desktop under a proper name.

Previously, DOSBox captures were stored in a folder called “capture”
within the current working directory of the process, which was usually
not where the user would expect to find their files.
  • Loading branch information...
alunbestor committed Nov 30, 2014
1 parent eacbae7 commit fea07ef3278951527c8d42aee30a95ebfb76dbf6
View
@@ -34,6 +34,7 @@ extern "C" {
#define GFX_GetBestMode boxer_idealOutputMode
#define GFX_ShowMsg boxer_log
#define MIDI_Available boxer_MIDIAvailable
#define OpenCaptureFile boxer_openCaptureFile
#define E_Exit(format,...) boxer_die(__PRETTY_FUNCTION__, __FILE__, __LINE__, format, ##__VA_ARGS__)
class DOS_Drive;
View
@@ -229,6 +229,12 @@ bool boxer_shellShouldDisplayStartupMessages(DOS_Shell *shell)
#pragma mark - Filesystem functions
FILE *boxer_openCaptureFile(const char *typeDescription, const char *fileExtension)
{
BXEmulator *emulator = [BXEmulator currentEmulator];
return [emulator _openFileForCaptureOfType:typeDescription extension: fileExtension];
}
//Whether or not to allow the specified path to be mounted.
//Called by MOUNT::Run in DOSBox's dos/dos_programs.cpp.
bool boxer_shouldMountPath(const char *path)
@@ -1405,6 +1405,17 @@ - (NSURL *) _logicalURLForDOSPath: (const char *)dosCPath
return [drive logicalURLForDOSPath: dosPath];
}
- (FILE *) _openFileForCaptureOfType: (const char *)typeDescription extension: (const char *)fileExtension
{
NSString *type = [NSString stringWithUTF8String: typeDescription];
NSString *ext = [NSString stringWithUTF8String: fileExtension];
//Strip off DOSBox's leading extension separators
if ([ext hasPrefix: @"."])
ext = [ext substringFromIndex: 1];
return [self.delegate emulator: self openCaptureFileOfType: type extension: ext];
}
- (FILE *) _openFileAtLocalPath: (const char *)path
onDOSBoxDrive: (DOS_Drive *)dosboxDrive
inMode: (const char *)mode
@@ -219,6 +219,11 @@ extern NSString * const BXEmulatorDidRemoveFileNotification;
/// @return @c YES to allow the emulator to write to the specified file location, or @c NO otherwise.
- (BOOL) emulator: (BXEmulator *)emulator shouldAllowWriteAccessToURL: (NSURL *)fileURL onDrive: (BXDrive *)drive;
/// Called when the emulator wants to capture output to a file.
/// Return an open file handle which will later be closed by the emulator once capturing is complete.
/// Return nil if the emulator is not permitted to capture files.
- (FILE *) emulator: (BXEmulator *)emulator openCaptureFileOfType: (NSString *)captureType extension: (NSString *)extension;
@optional
/// Called when a DOS drive has been mounted. Corresponds to @c BXEmulatorDriveDidMountNotification.
View
@@ -374,7 +374,6 @@ enum {
- (BOOL) _shouldAllowWriteAccessToLocalPath: (const char *)localPath
onDOSBoxDrive: (DOS_Drive *)dosboxDrive;
#pragma mark - Local filesystem access
/// Resolves a DOS path on a particular drive to a local filesystem URL.
@@ -395,6 +394,16 @@ enum {
- (NSURL *) _logicalURLForDOSPath: (const char *)dosPath
onDOSBoxDrive: (DOS_Drive *)dosboxDrive;
/// Opens a local file handle for DOSBox to record captured output to, in write-only mode.
/// DOSBox is expected to close the file when done.
/// @note Passes the decision on to the delegate via -emulator:openCaptureFileOfType:description:.
/// @param typeDescription A string describing the type of data to be captured.
/// @param fileExtension The suggested file extension to use for that data.
/// @return An open file handle for DOSBox to record into, or @c nil if capturing is not permitted.
- (FILE *) _openFileForCaptureOfType: (const char *)typeDescription
extension: (const char *)fileExtension;
/// Attempts to open a file on the local filesystem.
/// @param localPath The POSIX path to the file on the local filesystem which should be opened.
/// @param dosboxDrive The DOSBox drive from which the file is being opened.
@@ -445,4 +445,10 @@ typedef NS_OPTIONS(NSUInteger, BXDriveMountOptions) {
//Called when a drive has finished importing. Replaces the source drive with the imported version.
- (void) driveImportDidFinish: (NSNotification *)theNotification;
#pragma mark - Captures
/// Returns a file URL suitable for capturing a file of the specified type and extension.
- (NSURL *) URLForCaptureOfType: (NSString *)typeDescription
fileExtension: (NSString *)extension;
@end
@@ -2212,4 +2212,60 @@ - (void) _applicationDidBecomeActive: (NSNotification *)notification
}
}
#pragma mark - Captures
- (NSURL *) URLForCaptureOfType: (NSString *)typeDescription fileExtension: (NSString *)extension
{
NSString *descriptiveSuffix = @"";
//Remap certain of DOSBox's file type suggestions.
if ([typeDescription isEqualToString: @"Parallel Port Stream"]) //Parallel-port dumps
{
descriptiveSuffix = @" LPT output";
extension = @"txt";
}
//Work out an appropriate filename, based on the title of the session and the current date and time.
NSValueTransformer *transformer = [NSValueTransformer valueTransformerForName: @"BXCaptureDateTransformer"];
NSString *formattedDate = [transformer transformedValue: [NSDate date]];
NSString *nameFormat = NSLocalizedString(@"%1$@%2$@ %3$@",
@"Filename pattern for captures: %1$@ is the display name of the DOS session, %2$@ is the type of capture being created, %3$@ is the current date and time in a notation suitable for chronologically-ordered filenames.");
//Name the captured file after the current gamebox, or - failing that - the application itself.
NSString *sessionName = self.displayName;
if (sessionName.length == 0)
sessionName = [BXBaseAppController appName];
NSString *baseName = [NSString stringWithFormat: nameFormat, sessionName, descriptiveSuffix, formattedDate];
NSString *fileName = [baseName stringByAppendingPathExtension: extension];
//Sanitise the filename in case it contains characters that are disallowed for file paths.
//TODO: move this off to an NSFileManager/NSString category.
fileName = [fileName stringByReplacingOccurrencesOfString: @":" withString: @"-"];
fileName = [fileName stringByReplacingOccurrencesOfString: @"/" withString: @"-"];
NSURL *baseURL = [(BXBaseAppController *)[NSApp delegate] recordingsURLCreatingIfMissing: YES error: NULL];
NSURL *destinationURL = [baseURL URLByAppendingPathComponent: fileName];
return destinationURL;
}
- (FILE *) emulator: (BXEmulator *)emulator openCaptureFileOfType: (NSString *)captureType extension: (NSString *)extension
{
NSURL *URL = [self URLForCaptureOfType: captureType fileExtension: extension];
if (URL != nil)
{
const char *fsRepresentation = URL.fileSystemRepresentation;
FILE *handle = fopen(fsRepresentation, "wb");
//TODO: should we hide the file extension for common file types like txt and png?
return handle;
}
else
{
return nil;
}
}
@end
@@ -56,7 +56,7 @@ + (void) initialize
[NSValueTransformer setValueTransformer: speedBanding forName: @"BXSpeedSliderTransformer"];
[NSValueTransformer setValueTransformer: invertFramerate forName: @"BXFrameRateSliderTransformer"];
[NSValueTransformer setValueTransformer: screenshotDater forName: @"BXScreenshotDateTransformer"];
[NSValueTransformer setValueTransformer: screenshotDater forName: @"BXCaptureDateTransformer"];
[speedBanding release];
[invertFramerate release];
@@ -750,24 +750,7 @@ - (IBAction) saveScreenshot: (id)sender
NSImage *screenshot = [self.DOSWindowController screenshotOfCurrentFrame];
if (screenshot)
{
//Work out an appropriate filename, based on the window title and the current date and time.
NSValueTransformer *transformer = [NSValueTransformer valueTransformerForName: @"BXScreenshotDateTransformer"];
NSString *formattedDate = [transformer transformedValue: [NSDate date]];
NSString *nameFormat = NSLocalizedString(@"%1$@ %2$@.png",
@"Filename pattern for screenshots: %1$@ is the display name of the DOS session, %2$@ is the current date and time in a notation suitable for chronologically-ordered filenames.");
NSString *windowTitle = self.DOSWindowController.window.title;
NSString *fileName = [NSString stringWithFormat: nameFormat, windowTitle, formattedDate];
//Sanitise the filename in case it contains characters that are disallowed for file paths.
//TODO: move this off to an NSFileManager/NSString category.
fileName = [fileName stringByReplacingOccurrencesOfString: @":" withString: @"-"];
fileName = [fileName stringByReplacingOccurrencesOfString: @"/" withString: @"-"];
NSURL *baseURL = [(BXBaseAppController *)[NSApp delegate] recordingsURLCreatingIfMissing: YES error: NULL];
NSURL *destinationURL = [baseURL URLByAppendingPathComponent: fileName];
NSURL *destinationURL = [self URLForCaptureOfType: @"Screenshot" fileExtension: @"png"];
BOOL saved = [screenshot saveToURL: destinationURL
withType: NSPNGFileType
properties: nil
@@ -1065,7 +1048,7 @@ - (IBAction) exportGameState: (id)sender
//Work out a suitable filename, based on the game name and the current date.
NSString *nameFormat = NSLocalizedString(@"%1$@ %2$@", @"The filename format under which to save exported game states. %1$@ is the name of the current game. %2$@ is the current date and time.");
NSValueTransformer *transformer = [NSValueTransformer valueTransformerForName: @"BXScreenshotDateTransformer"];
NSValueTransformer *transformer = [NSValueTransformer valueTransformerForName: @"BXCaptureDateTransformer"];
NSString *formattedDate = [transformer transformedValue: [NSDate date]];
NSString *baseName = [NSString stringWithFormat: nameFormat, self.displayName, formattedDate];
@@ -82,6 +82,9 @@ static struct {
#endif
} capture;
//Overridden 2014-11-30 by Alun Bestor to allow Boxer to decide where captured files should go and what they should be named.
/*
FILE * OpenCaptureFile(const char * type,const char * ext) {
if(capturedir.empty()) {
@@ -124,7 +127,7 @@ FILE * OpenCaptureFile(const char * type,const char * ext) {
sprintf(file_name,"%s%c%s%03d%s",capturedir.c_str(),CROSS_FILESPLIT,file_start,last,ext);
/* Open the actual file */
// Open the actual file
FILE * handle=fopen(file_name,"wb");
if (handle) {
LOG_MSG("Capturing %s to %s",type,file_name);
@@ -133,6 +136,7 @@ FILE * OpenCaptureFile(const char * type,const char * ext) {
}
return handle;
}
*/
#if (C_SSHOT)
static void CAPTURE_AddAviChunk(const char * tag, Bit32u size, void * data, Bit32u flags) {

0 comments on commit fea07ef

Please sign in to comment.