5
// Created by Jean-Francois Roy on 26/03/2007.
6
// Copyright MacStorm 2007. All rights reserved.
9
#import <Foundation/Foundation.h>
12
#import "MPQFileSystem.h"
14
#define FUSE_USE_VERSION 26
15
#define _FILE_OFFSET_BITS 64
18
static NSString *archive_path = nil;
19
static NSMutableArray *listfiles = nil;
20
static NSString *mount_point = nil;
22
static BOOL has_volname = NO;
23
static NSString *mount_icon = nil;
32
#define MPQFS_OPT(t, p, v) { t, offsetof(struct sshfs, p), v }
33
static struct fuse_opt mpqfs_opts[] = {
34
FUSE_OPT_KEY("-l ", KEY_LISTFILE),
35
FUSE_OPT_KEY("--listfile=", KEY_LISTFILE),
36
FUSE_OPT_KEY("-i ", KEY_VOLICON),
37
FUSE_OPT_KEY("--icon=", KEY_VOLICON),
38
FUSE_OPT_KEY("--version", KEY_VERSION),
39
FUSE_OPT_KEY("-h", KEY_HELP),
40
FUSE_OPT_KEY("--help", KEY_HELP),
44
static void usage(const char *program) {
46
"usage: %s archive mountpoint [options]\n"
49
" -o opt,[opt...] mount options\n"
50
" -h --help print help\n"
51
" -V --version print version\n"
54
" -l --listfile supply an external listfile to MPQFS\n"
55
" -i --icon specify a volume icon file for the Finder\n"
59
static struct fuse_operations dummy_opts;
61
static int mpqfs_opt_proc(void *data, const char *arg, int key, struct fuse_args *outargs) {
63
case FUSE_OPT_KEY_OPT:
64
if (strstr(arg, "volname") != NULL) {
69
case FUSE_OPT_KEY_NONOPT:
71
archive_path = [[NSString alloc] initWithCString:arg encoding:NSUTF8StringEncoding];
75
mount_point = [[NSString alloc] initWithCString:arg encoding:NSUTF8StringEncoding];
81
NSLog(@"KEY_LISTFILE: %s", arg);
85
NSLog(@"KEY_VOLICON: %s", arg);
86
[mount_icon release]; mount_icon = nil;
87
if (strstr(arg, "-i") == arg) mount_icon = [[[NSString stringWithCString:arg + 2 encoding:NSUTF8StringEncoding] stringByStandardizingPath] retain];
88
if (strstr(arg, "--icon=") == arg) mount_icon = [[[NSString stringWithCString:arg + 7 encoding:NSUTF8StringEncoding] stringByStandardizingPath] retain];
92
usage(outargs->argv[0]);
93
fuse_opt_add_arg(outargs, "-ho");
94
fuse_main(outargs->argc, outargs->argv, &dummy_opts, NULL);
98
fprintf(stderr, "MPQFS version %s\n", "0.1");
99
fuse_opt_add_arg(outargs, "--version");
100
fuse_main(outargs->argc, outargs->argv, &dummy_opts, NULL);
104
fprintf(stderr, "internal error\n");
109
int main(int argc, char *argv[]) {
110
NSAutoreleasePool *p = [NSAutoreleasePool new];
111
NSError *error = nil;
113
struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
114
listfiles = [[NSMutableArray alloc] init];
116
if (fuse_opt_parse(&args, NULL, mpqfs_opts, mpqfs_opt_proc) == -1) exit(1);
118
if (archive_path == nil) {
119
fprintf(stderr, "missing archive path\n");
120
fprintf(stderr, "see `%s -h' for usage\n", argv[0]);
124
if (mount_point == nil) {
125
fprintf(stderr, "missing mount point\n");
126
fprintf(stderr, "see `%s -h' for usage\n", argv[0]);
130
MPQArchive *archive = [[MPQArchive alloc] initWithPath:archive_path error:&error];
132
fprintf(stderr, "error opening archive: %s\n", [[error description] UTF8String]);
133
fprintf(stderr, "see `%s -h' for usage\n", argv[0]);
136
[archive_path release];
138
if ([listfiles count] > 0) {
143
MPQFileSystem *fs = [[MPQFileSystem alloc] initWithArchive:archive mountPoint:mount_point arguments:&args error:&error];
145
fprintf(stderr, "error creating MPQ filesystem: %s\n", [[error description] UTF8String]);
150
[mount_point release];
153
[fs setValue:[NSNumber numberWithBool:(has_volname) ? NO : YES] forKey:@"overwriteVolname"];
154
if (mount_icon) [fs setValue:mount_icon forKey:@"mountIcon"];
155
[mount_icon release];
157
// Start fuse (does not return until unmount)
165
fuse_opt_free_args(&args);