mirror of
https://github.com/ksherlock/ample.git
synced 2025-04-07 13:38:01 +00:00
add download url / extension fields.
This commit is contained in:
parent
cabffd23ea
commit
f9d4489e48
@ -21,4 +21,10 @@ extern NSString *kMameWorkingDirectory;
|
||||
extern NSString *kAutoCloseLogWindow;
|
||||
extern NSString *kMameComponentsDate;
|
||||
|
||||
extern NSString *kDownloadURL;
|
||||
extern NSString *kDownloadExtension;
|
||||
|
||||
extern NSString *kDefaultDownloadURL;
|
||||
extern NSString *kDefaultDownloadExtension;
|
||||
|
||||
#endif /* Ample_h */
|
||||
|
@ -40,3 +40,8 @@ NSString *kMamePath = @"MamePath";
|
||||
NSString *kMameWorkingDirectory = @"MameWorkingDirectory";
|
||||
NSString *kAutoCloseLogWindow = @"AutoCloseLogWindow";
|
||||
NSString *kMameComponentsDate = @"MameComponentsDate";
|
||||
NSString *kDefaultDownloadURL = @"DefaultDownloadURL";
|
||||
NSString *kDefaultDownloadExtension = @"DefaultDownloadExtension";
|
||||
|
||||
NSString *kDownloadURL = @"DownloadURL";
|
||||
NSString *kDownloadExtension = @"DownloadExtension";
|
||||
|
@ -8,6 +8,8 @@
|
||||
<objects>
|
||||
<customObject id="-2" userLabel="File's Owner" customClass="DownloadWindowController">
|
||||
<connections>
|
||||
<outlet property="downloadField" destination="sJz-So-jbA" id="WjK-48-FcE"/>
|
||||
<outlet property="formatButton" destination="2Rg-eX-DUq" id="oYo-MG-Sc6"/>
|
||||
<outlet property="tableView" destination="FLX-Wt-y53" id="a4O-pk-EAt"/>
|
||||
<outlet property="window" destination="F0z-JX-Cv5" id="gIp-Ho-8D9"/>
|
||||
</connections>
|
||||
@ -16,11 +18,11 @@
|
||||
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
|
||||
<window title="ROMs" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" frameAutosaveName="DownloadManagerWindow" animationBehavior="default" id="F0z-JX-Cv5">
|
||||
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES"/>
|
||||
<rect key="contentRect" x="196" y="240" width="400" height="500"/>
|
||||
<rect key="contentRect" x="196" y="240" width="400" height="575"/>
|
||||
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1417"/>
|
||||
<value key="minSize" type="size" width="300" height="300"/>
|
||||
<view key="contentView" id="se5-gp-TjO">
|
||||
<rect key="frame" x="0.0" y="0.0" width="400" height="500"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="400" height="575"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="rg5-Qf-4Mw">
|
||||
@ -40,14 +42,14 @@
|
||||
</connections>
|
||||
</button>
|
||||
<scrollView fixedFrame="YES" autohidesScrollers="YES" horizontalLineScroll="51" horizontalPageScroll="10" verticalLineScroll="51" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="CMD-nT-mEa">
|
||||
<rect key="frame" x="0.0" y="58" width="402" height="443"/>
|
||||
<rect key="frame" x="0.0" y="130" width="402" height="446"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<clipView key="contentView" ambiguous="YES" drawsBackground="NO" id="Igp-aH-flp">
|
||||
<rect key="frame" x="1" y="1" width="400" height="441"/>
|
||||
<rect key="frame" x="1" y="1" width="400" height="444"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<tableView verticalHuggingPriority="750" ambiguous="YES" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" selectionHighlightStyle="none" alternatingRowBackgroundColors="YES" columnReordering="NO" columnResizing="NO" multipleSelection="NO" autosaveColumns="NO" rowHeight="49" rowSizeStyle="automatic" viewBased="YES" id="FLX-Wt-y53">
|
||||
<rect key="frame" x="0.0" y="0.0" width="400" height="441"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="400" height="444"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<size key="intercellSpacing" width="3" height="2"/>
|
||||
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
@ -139,6 +141,18 @@
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
</scroller>
|
||||
</scrollView>
|
||||
<textField verticalHuggingPriority="750" fixedFrame="YES" textCompletion="NO" translatesAutoresizingMaskIntoConstraints="NO" id="sJz-So-jbA">
|
||||
<rect key="frame" x="51" y="101" width="329" height="21"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" id="HKe-di-YSs">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
<connections>
|
||||
<action selector="downloadURLChanged:" target="-2" id="ah1-QS-G27"/>
|
||||
</connections>
|
||||
</textField>
|
||||
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Fhd-vr-Q2G">
|
||||
<rect key="frame" x="20" y="19" width="124" height="23"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
@ -155,12 +169,56 @@
|
||||
</binding>
|
||||
</connections>
|
||||
</button>
|
||||
<popUpButton verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="2Rg-eX-DUq">
|
||||
<rect key="frame" x="49" y="60" width="98" height="25"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<popUpButtonCell key="cell" type="push" title="zip" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" tag="1" imageScaling="proportionallyDown" inset="2" autoenablesItems="NO" selectedItem="7Cq-Lh-dgg" id="uum-dC-XD0">
|
||||
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="menu"/>
|
||||
<menu key="menu" autoenablesItems="NO" id="kcg-aZ-mD9">
|
||||
<items>
|
||||
<menuItem title="zip" state="on" tag="1" id="7Cq-Lh-dgg"/>
|
||||
<menuItem title="7z" tag="2" id="s5r-gg-Ma9"/>
|
||||
</items>
|
||||
</menu>
|
||||
</popUpButtonCell>
|
||||
<connections>
|
||||
<action selector="downloadExtensionChanged:" target="-2" id="tp2-tg-bms"/>
|
||||
<binding destination="-2" name="selectedTag" keyPath="self.downloadExtension" id="uck-nA-UPg">
|
||||
<dictionary key="options">
|
||||
<string key="NSValueTransformerName">DownloadExtensionTransformer</string>
|
||||
</dictionary>
|
||||
</binding>
|
||||
</connections>
|
||||
</popUpButton>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="d2z-4T-Wh1">
|
||||
<rect key="frame" x="10" y="104" width="30" height="16"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<textFieldCell key="cell" lineBreakMode="clipping" title="URL" id="lcZ-R4-WsS">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ZXO-bJ-btp">
|
||||
<rect key="frame" x="11" y="66" width="34" height="16"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<textFieldCell key="cell" lineBreakMode="clipping" title="Type" id="KGI-t9-OMF">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<box verticalHuggingPriority="750" fixedFrame="YES" boxType="separator" translatesAutoresizingMaskIntoConstraints="NO" id="AuM-pD-Gul">
|
||||
<rect key="frame" x="12" y="52" width="368" height="5"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
|
||||
</box>
|
||||
</subviews>
|
||||
</view>
|
||||
<connections>
|
||||
<outlet property="delegate" destination="-2" id="0bl-1N-AYu"/>
|
||||
</connections>
|
||||
<point key="canvasLocation" x="142" y="179"/>
|
||||
<point key="canvasLocation" x="32" y="119.5"/>
|
||||
</window>
|
||||
<menu id="RJM-21-hjO">
|
||||
<items>
|
||||
@ -188,5 +246,6 @@
|
||||
</connections>
|
||||
<point key="canvasLocation" x="-348" y="164"/>
|
||||
</menu>
|
||||
<userDefaultsController representsSharedInstance="YES" id="721-9N-Bma"/>
|
||||
</objects>
|
||||
</document>
|
||||
|
@ -10,7 +10,13 @@
|
||||
<true/>
|
||||
<key>MamePath</key>
|
||||
<string>/usr/local/bin/mame</string>
|
||||
<key>MameWorkingDirectory</key>
|
||||
<string>/usr/local/share/mame/</string>
|
||||
<key>NSQuitAlwaysKeepsWindows</key>
|
||||
<true/>
|
||||
<key>DefaultDownloadURL</key>
|
||||
<string>https://archive.org/download/mame225_rom</string>
|
||||
<key>DefaultDownloadExtension</key>
|
||||
<string>7z</string>
|
||||
</dict>
|
||||
</plist>
|
||||
|
@ -8,6 +8,67 @@
|
||||
|
||||
#import "Ample.h"
|
||||
#import "DownloadWindowController.h"
|
||||
#import "Menu.h"
|
||||
|
||||
|
||||
enum {
|
||||
kTagZip = 1,
|
||||
kTag7z = 2,
|
||||
};
|
||||
|
||||
@interface DownloadExtensionTransformer: NSValueTransformer
|
||||
@end
|
||||
|
||||
@implementation DownloadExtensionTransformer
|
||||
|
||||
+(void)load {
|
||||
[NSValueTransformer setValueTransformer: [DownloadExtensionTransformer new] forName: @"FormatTransformer"];
|
||||
|
||||
}
|
||||
|
||||
+ (Class)transformedValueClass {
|
||||
return [NSString class];
|
||||
}
|
||||
|
||||
+ (BOOL)allowsReverseTransformation {
|
||||
return YES;
|
||||
}
|
||||
|
||||
-(id)transformedValue:(id)value {
|
||||
// string to number.
|
||||
if ([@"zip" isEqualToString: value])
|
||||
return @(kTagZip);
|
||||
if ([@"7z" isEqualToString: value])
|
||||
return @(kTag7z);
|
||||
return @0;
|
||||
}
|
||||
|
||||
-(id)reverseTransformedValue:(id)value {
|
||||
// number back to string.
|
||||
switch ([value intValue]) {
|
||||
case kTagZip: return @"zip";
|
||||
case kTag7z: return @"7z";
|
||||
default: return @"";
|
||||
}
|
||||
}
|
||||
|
||||
+(unsigned)stringToNumber: (NSString *)string {
|
||||
if ([@"zip" isEqualToString: string])
|
||||
return kTagZip;
|
||||
if ([@"7z" isEqualToString: string])
|
||||
return kTag7z;
|
||||
return 0;
|
||||
}
|
||||
|
||||
+(NSString *)numberToString: (unsigned)number {
|
||||
switch (number) {
|
||||
case kTagZip: return @"zip";
|
||||
case kTag7z: return @"7z";
|
||||
default: return @"";
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
enum {
|
||||
ItemMissing = 0,
|
||||
@ -40,6 +101,9 @@ enum {
|
||||
|
||||
@interface DownloadWindowController ()
|
||||
@property (weak) IBOutlet NSTableView *tableView;
|
||||
@property (weak) IBOutlet NSPopUpButton *formatButton;
|
||||
@property (weak) IBOutlet NSTextField *downloadField;
|
||||
@property NSString *downloadExtension;
|
||||
|
||||
@end
|
||||
|
||||
@ -47,9 +111,12 @@ enum {
|
||||
|
||||
NSArray *_items;
|
||||
NSURL *_romFolder;
|
||||
NSURL *_sourceURL;
|
||||
NSURL *_defaultDownloadURL;
|
||||
NSURL *_downloadURL;
|
||||
|
||||
NSURLSession *_session;
|
||||
NSMutableDictionary *_taskIndex;
|
||||
NSUserDefaults *_defaults;
|
||||
}
|
||||
|
||||
+(instancetype)sharedInstance {
|
||||
@ -69,6 +136,7 @@ enum {
|
||||
completionHandler(w, nil);
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
- (void)encodeWithCoder:(nonnull NSCoder *)coder {
|
||||
|
||||
@ -79,11 +147,24 @@ enum {
|
||||
return @"DownloadWindow";
|
||||
}
|
||||
|
||||
-(void)windowWillLoad {
|
||||
_defaults = [NSUserDefaults standardUserDefaults];
|
||||
|
||||
// set here so binding works.
|
||||
NSString *s = [_defaults stringForKey: kDownloadExtension];
|
||||
if (![s length]) s = [_defaults stringForKey: kDefaultDownloadExtension];
|
||||
|
||||
_downloadExtension = s;
|
||||
}
|
||||
|
||||
- (void)windowDidLoad {
|
||||
[super windowDidLoad];
|
||||
#if 0
|
||||
NSWindow *window = [self window];
|
||||
// disabled for now ... restoration happens before defaults are loaded.
|
||||
[window setRestorable: YES];
|
||||
[window setRestorationClass: [self class]];
|
||||
#endif
|
||||
|
||||
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
|
||||
|
||||
@ -102,15 +183,29 @@ enum {
|
||||
|
||||
[fm createDirectoryAtURL: _romFolder withIntermediateDirectories: YES attributes: nil error: &error];
|
||||
|
||||
// so blank URL isn't overwritten.
|
||||
NSString *s = [_defaults stringForKey: kDefaultDownloadURL];
|
||||
_defaultDownloadURL = [NSURL URLWithString: s];
|
||||
[_downloadField setPlaceholderString: s];
|
||||
|
||||
s = [_defaults stringForKey: kDownloadURL];
|
||||
if ([s length]) {
|
||||
[_downloadField setStringValue: s];
|
||||
_downloadURL = [NSURL URLWithString: s];
|
||||
} else {
|
||||
_downloadURL = _defaultDownloadURL;
|
||||
}
|
||||
|
||||
[self initializeExtensionMenu];
|
||||
|
||||
|
||||
NSArray *roms = [d objectForKey: @"roms"];
|
||||
[self setCurrentROM: @""];
|
||||
[self setCurrentCount: 0];
|
||||
[self setTotalCount: [roms count]];
|
||||
[self setErrorCount: 0];
|
||||
_sourceURL = [NSURL URLWithString: @"https://archive.org/download/mame225_rom"]; // hardcoded....
|
||||
|
||||
|
||||
|
||||
NSMutableArray *tmp = [NSMutableArray arrayWithCapacity: [roms count]];
|
||||
unsigned ix = 0;
|
||||
for (NSString *name in roms) {
|
||||
@ -147,6 +242,27 @@ enum {
|
||||
//[self download];
|
||||
}
|
||||
|
||||
#if 0
|
||||
-(void)validateURL: (NSString *)url {
|
||||
NSURL *v;
|
||||
|
||||
if (![url length]) {
|
||||
_effectiveURL = [NSURL URLWithString: _downloadURL];
|
||||
[_downloadField setTextColor: nil];
|
||||
return;
|
||||
}
|
||||
|
||||
v = [NSURL URLWithString: url];
|
||||
if (v) {
|
||||
_effectiveURL = v;
|
||||
[_downloadField setTextColor: nil];
|
||||
} else {
|
||||
_effectiveURL = [NSURL URLWithString: _downloadURL];
|
||||
[_downloadField setTextColor: [NSColor redColor]];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
-(void)downloadItem: (DownloadItem *)item {
|
||||
|
||||
if (!_session) {
|
||||
@ -156,8 +272,8 @@ enum {
|
||||
|
||||
NSURLSessionDownloadTask *task;
|
||||
NSString *s = [item name];
|
||||
NSString *path = [s stringByAppendingString: @".7z"]; // hardcoded.
|
||||
NSURL *url = [_sourceURL URLByAppendingPathComponent: path];
|
||||
NSString *path = [s stringByAppendingPathExtension: _downloadExtension];
|
||||
NSURL *url = [_downloadURL URLByAppendingPathComponent: path];
|
||||
|
||||
task = [_session downloadTaskWithURL: url];
|
||||
|
||||
@ -170,16 +286,15 @@ enum {
|
||||
|
||||
-(void)download {
|
||||
|
||||
|
||||
|
||||
// run in thread?
|
||||
//unsigned count = 0;
|
||||
|
||||
for (DownloadItem *item in _items) {
|
||||
|
||||
NSURLSessionDownloadTask *task;
|
||||
NSString *s = [item name];
|
||||
NSString *path = [s stringByAppendingString: @".7z"]; // hardcoded.
|
||||
NSURL *url = [_sourceURL URLByAppendingPathComponent: path];
|
||||
NSString *path = [s stringByAppendingPathExtension: _downloadExtension];
|
||||
NSURL *url = [_downloadURL URLByAppendingPathComponent: path];
|
||||
|
||||
task = [_session downloadTaskWithURL: url];
|
||||
[_taskIndex setObject: item forKey: task];
|
||||
@ -210,6 +325,31 @@ enum {
|
||||
|
||||
[_tableView reloadDataForRowIndexes: rIx columnIndexes: cIx];
|
||||
}
|
||||
|
||||
|
||||
-(void)initializeExtensionMenu {
|
||||
|
||||
unsigned tag;
|
||||
// mark default download extension.
|
||||
NSString *defaultExt = [_defaults stringForKey: kDefaultDownloadExtension];
|
||||
tag = [DownloadExtensionTransformer stringToNumber: defaultExt];
|
||||
|
||||
NSMenuItem *item = [[_formatButton menu] itemWithTag: tag];
|
||||
if (item) {
|
||||
[item setAttributedTitle: ItalicMenuString([item title])];
|
||||
}
|
||||
|
||||
#if 0
|
||||
// handled via binding.
|
||||
NSString *ext = [_defaults stringForKey: kDownloadExtension];
|
||||
if ([ext length]) {
|
||||
ix = [DownloadExtensionTransformer stringToNumber: ext];
|
||||
}
|
||||
|
||||
[_formatButton selectItemWithTag: tag];
|
||||
#endif
|
||||
}
|
||||
|
||||
#pragma mark - IBActions
|
||||
|
||||
-(IBAction)cancelAll:(id)sender {
|
||||
@ -272,6 +412,22 @@ enum {
|
||||
[self redrawRow: [item index]];
|
||||
}
|
||||
|
||||
// binding screws up with placeholder.
|
||||
-(IBAction)downloadURLChanged: (NSTextField *)sender {
|
||||
NSString *value;
|
||||
value = [sender stringValue];
|
||||
if (![value length]) {
|
||||
[_defaults removeObjectForKey: kDownloadURL];
|
||||
_downloadURL = _defaultDownloadURL;
|
||||
return;
|
||||
}
|
||||
// [self validateURL: value];
|
||||
[_defaults setValue: value forKey: kDownloadURL];
|
||||
_downloadURL = [NSURL URLWithString: value];
|
||||
}
|
||||
- (IBAction)downloadExtensionChanged:(id)sender {
|
||||
[_defaults setValue: _downloadExtension forKey: kDownloadExtension];
|
||||
}
|
||||
|
||||
#pragma mark - NSURLSessionDelegate
|
||||
|
||||
@ -352,22 +508,23 @@ enum {
|
||||
DownloadTableCellView *v = [tableView makeViewWithIdentifier: @"DownloadCell" owner: self];
|
||||
|
||||
NSTextField *tf;
|
||||
NSColor *redColor = [NSColor systemRedColor];
|
||||
|
||||
tf = [v textField];
|
||||
[[v textField] setObjectValue: [item name]];
|
||||
|
||||
if ([item localURL]) {
|
||||
[tf setTextColor: [NSColor blackColor]];
|
||||
[tf setTextColor: nil];
|
||||
} else {
|
||||
[tf setTextColor: [NSColor redColor]];
|
||||
[tf setTextColor: redColor];
|
||||
}
|
||||
|
||||
tf = [v statusTextField];
|
||||
[tf setObjectValue: [item statusDescription]];
|
||||
if ([item error]) {
|
||||
[tf setTextColor: [NSColor redColor]];
|
||||
[tf setTextColor: redColor];
|
||||
} else {
|
||||
[tf setTextColor: [NSColor blackColor]];
|
||||
[tf setTextColor: nil];
|
||||
//if ([tableView isRowSelected: row]){
|
||||
//[tf setTextColor: [NSColor whiteColor]];
|
||||
//}
|
||||
@ -447,6 +604,9 @@ enum {
|
||||
};
|
||||
|
||||
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
|
||||
|
||||
if ([menuItem action] == @selector(downloadExtensionChanged:)) return YES;
|
||||
|
||||
NSInteger row = [_tableView clickedRow];
|
||||
if (row < 0) return NO;
|
||||
DownloadItem *item = [_items objectAtIndex: row];
|
||||
|
Loading…
x
Reference in New Issue
Block a user