aboutsummaryrefslogtreecommitdiff
path: root/Src/Plugins/SDK/burner/ISOBurner.cpp
blob: 84d45f62f387e7472853ded5f248e86c3ed9d97d (plain) (blame)
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
#include "ISOBurner.h"
#include "../nu/AutoChar.h"
#include "ifc_burner_writecallback.h"

ISOBurner::ISOBurner(obj_primo *_primo) : BurnerCommon(_primo)
{
}

int ISOBurner::Open()
{
	if (!primo)
		return 1;

	return 0;
}

int ISOBurner::Write(wchar_t driveLetter, const wchar_t *isoFile, int flags, unsigned int speed, ifc_burner_writecallback *callback)
{
	DWORD unit[] = {driveLetter, 0xFFFFFFFF};
	DWORD ret = primo->WriteOtherCDImage(unit, (PBYTE)(char *)AutoChar(isoFile), flags, speed);
	if (ret != PRIMOSDK_OK)
		return 1;

	while (1)
	{
		DWORD cursec = 0, totsec = 0;
		ret = primo->RunningStatus(PRIMOSDK_GETSTATUS, &cursec, &totsec);

		if (ret == PRIMOSDK_RUNNING)
		{
			if (callback)
			{
				int abort = callback->OnStatus(cursec, totsec);
				if (abort)
				{
					ret = primo->RunningStatus(PRIMOSDK_ABORT, 0, 0);
					callback = 0; // cheap way to prevent making further callbacks
				}
			}
			WaitForSingleObject(triggerEvent, 500);
		}
		else if (ret == PRIMOSDK_OK)
		{
			DWORD unit = driveLetter;
			ret = primo->UnitStatus(&unit, NULL, NULL, NULL, NULL);

			if (ret == PRIMOSDK_OK && callback)
				callback->Finished();
			break;
		}
		else
			break;
	}

	if (ret != PRIMOSDK_OK)
		return 1;

	return 0;
}

#define CBCLASS ISOBurner
START_DISPATCH;
CB(ISOBURNER_OPEN, Open)
CB(ISOBURNER_WRITE, Write)
VCB(ISOBURNER_FORCECALLBACK, ForceCallback)
END_DISPATCH;
#undef CBCLASS