-
Notifications
You must be signed in to change notification settings - Fork 1
/
nidmount.c
100 lines (91 loc) · 3.06 KB
/
nidmount.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#ifdef TINYFILE
#include "tinyfile.h"
#endif
/* ================================================================
== Ahead Nero 6 ImageDrive mount/unmount routine ===============
================================================================ */
static char RegNeroPath[] = "SOFTWARE\\Ahead\\shared";
static char RegNeroName[] = "Nero6DefaultPath";
static char ImageDrvDll[] = "\\ImageDrive\\imagedrv.dll";
/*
! MUST be called FIRST and BEFORE any other functions !
input:
none
output:
version number in format ((major*100) + minor) i.e. 229 -> 2.29
*/
typedef int (WINAPI *LPImagedrvGetVersion)(void);
/*
input:
data - unknown optional value
file - image filename to mount or empty string "" to unmount current
output:
-1 - ImagedrvGetVersion() not called, library not initialized
0 - operation completed successful (no errors)
1001 - can't find or open specified file
1500 - can't mount / unsupported .ISO/.NRG CD/DVD image file (?)
*/
typedef int (WINAPI *LPImagedrvMountImage)(char *data, char *file);
int NIDMountImage(char *filename) {
LPImagedrvGetVersion ImagedrvGetVersion;
LPImagedrvMountImage ImagedrvMountImage;
char path[MAX_PATH], *pn;
HMODULE hl;
DWORD sz;
int rt;
HKEY hk;
rt = -1;
if (filename) {
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, RegNeroPath, 0, KEY_READ, &hk) == ERROR_SUCCESS) {
sz = MAX_PATH;
*path = 0;
if (RegQueryValueEx(hk, RegNeroName, NULL, NULL, (BYTE *) path, &sz) != ERROR_SUCCESS) {
*path = 0;
}
RegCloseKey(hk);
if (*path) {
lstrcat(path, ImageDrvDll);
hl = LoadLibrary(path);
if (hl) {
ImagedrvGetVersion = (LPImagedrvGetVersion) GetProcAddress(hl, MAKEINTRESOURCE(1));
ImagedrvMountImage = (LPImagedrvMountImage) GetProcAddress(hl, MAKEINTRESOURCE(2));
if (ImagedrvGetVersion && ImagedrvMountImage) {
*path = 0;
GetFullPathName(filename, MAX_PATH, path, &pn);
/*rt = */ImagedrvGetVersion();
/* printf("Ahead Nero 6 ImageDrive v%d.%d found\n", rt/100, rt%100);*/
rt = ImagedrvMountImage(NULL, path);
}
FreeLibrary(hl);
}
}
}
}
return(rt);
}
/* ================================================================
================================================================
================================================================ */
char *basename(char *s) {
char *r;
for (r = s; *s; s++) {
if ((*s == '/') || (*s == '\\')) {
r = &s[1];
}
}
return(r);
}
int main(int argc, char *argv[]) {
int rt;
printf("Ahead Nero 6 ImageDrive commandline mount v1.0\n(c) SysTools 2015\nhttp://systools.losthost.org/?misc\n\n");
if (argc == 2) {
rt = NIDMountImage(argv[1]);
printf("Drive %smount %s (code: %d)\n", (*argv[1] ? "" : "un"), (rt ? "error" : "successful"), rt);
} else {
printf("Mount image:\n%s filename.ext\n\nUnmount image (empty path):\n%s \"\"\n", basename(argv[0]), basename(argv[0]));
}
return(0);
}