mirror of
https://github.com/ErnyTech/Open-USB-Extreme
synced 2025-01-15 04:57:33 +01:00
Rename variables in D style
This commit is contained in:
parent
009f094c01
commit
4caee1c98f
@ -3,8 +3,8 @@ import core.stdc.stdlib;
|
|||||||
import usbextreme;
|
import usbextreme;
|
||||||
|
|
||||||
extern(C) int main(int argc, char[]* argv) {
|
extern(C) int main(int argc, char[]* argv) {
|
||||||
usb_extreme_headers headers;
|
UsbExtremeHeaders headers;
|
||||||
usb_extreme_filestat[10] filestatsBuf = void;
|
UsbExtremeFilestat[10] filestatsBuf = void;
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
printf("Usage: open-usbextreme-example <path/to/ul.cfg>\n");
|
printf("Usage: open-usbextreme-example <path/to/ul.cfg>\n");
|
||||||
|
@ -5,8 +5,8 @@ enum USBEXTREME_NAME_LENGTH = 32;
|
|||||||
enum USBEXTREME_ID_LENGTH = 15;
|
enum USBEXTREME_ID_LENGTH = 15;
|
||||||
enum USBEXTREME_NAME_EXT_LENGTH = 10;
|
enum USBEXTREME_NAME_EXT_LENGTH = 10;
|
||||||
enum USBEXTREME_MAGIC = 8;
|
enum USBEXTREME_MAGIC = 8;
|
||||||
enum USBEXTREME_HEADER_SIZE = usb_extreme_base.sizeof;
|
enum USBEXTREME_HEADER_SIZE = UsbExtremeBase.sizeof;
|
||||||
align (1) struct usb_extreme_base
|
align (1) struct UsbExtremeBase
|
||||||
{
|
{
|
||||||
align (1)
|
align (1)
|
||||||
{
|
{
|
||||||
@ -15,7 +15,7 @@ align (1) struct usb_extreme_base
|
|||||||
uint8_t[10] empty2;
|
uint8_t[10] empty2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
align (1) struct usb_extreme_v0
|
align (1) struct UsbExtremeV0
|
||||||
{
|
{
|
||||||
align (1)
|
align (1)
|
||||||
{
|
{
|
||||||
@ -28,7 +28,7 @@ align (1) struct usb_extreme_v0
|
|||||||
uint8_t[USBEXTREME_NAME_EXT_LENGTH] empty2;
|
uint8_t[USBEXTREME_NAME_EXT_LENGTH] empty2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
align (1) struct usb_extreme_v1
|
align (1) struct UsbExtremeV1
|
||||||
{
|
{
|
||||||
align (1)
|
align (1)
|
||||||
{
|
{
|
||||||
@ -37,28 +37,28 @@ align (1) struct usb_extreme_v1
|
|||||||
uint8_t n_parts;
|
uint8_t n_parts;
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
uint16_t size;
|
uint16_t size;
|
||||||
uint8_t video_mode;
|
uint8_t videoMode;
|
||||||
uint8_t usb_extreme_version;
|
uint8_t usbExtremeVersion;
|
||||||
uint8_t magic;
|
uint8_t magic;
|
||||||
char[USBEXTREME_NAME_EXT_LENGTH] name_ext;
|
char[USBEXTREME_NAME_EXT_LENGTH] nameExt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
struct usb_extreme_headers
|
struct UsbExtremeHeaders
|
||||||
{
|
{
|
||||||
const(void)* first_header;
|
const(void)* firstHeader;
|
||||||
const(usb_extreme_base)[] headers;
|
const(UsbExtremeBase)[] headers;
|
||||||
int num_headers;
|
int numHeaders;
|
||||||
size_t headerslen;
|
size_t headersLen;
|
||||||
UsbExtremeVersion oueVersion;
|
UsbExtremeVersion oueVersion;
|
||||||
}
|
}
|
||||||
struct usb_extreme_filestat
|
struct UsbExtremeFilestat
|
||||||
{
|
{
|
||||||
int offset;
|
int offset;
|
||||||
char[USBEXTREME_NAME_LENGTH + USBEXTREME_NAME_EXT_LENGTH] name;
|
char[USBEXTREME_NAME_LENGTH + USBEXTREME_NAME_EXT_LENGTH] name;
|
||||||
SCECdvdMediaType type;
|
SCECdvdMediaType type;
|
||||||
uint16_t size;
|
uint16_t size;
|
||||||
uint8_t video_mode;
|
uint8_t videoMode;
|
||||||
UsbExtremeVersion usb_extreme_version;
|
UsbExtremeVersion usbExtremeVersion;
|
||||||
}
|
}
|
||||||
enum UsbExtremeVersion
|
enum UsbExtremeVersion
|
||||||
{
|
{
|
||||||
@ -87,10 +87,10 @@ enum SCECdvdMediaType
|
|||||||
extern (D) bool isOue(const(void)[] headers);
|
extern (D) bool isOue(const(void)[] headers);
|
||||||
extern (D) UsbExtremeVersion getVersion(uint8_t usbExtremeVersion);
|
extern (D) UsbExtremeVersion getVersion(uint8_t usbExtremeVersion);
|
||||||
extern (D) int oueNumHeaders(const(void)[] headers);
|
extern (D) int oueNumHeaders(const(void)[] headers);
|
||||||
extern (D) int ouePointHeaders(ref const(usb_extreme_base)[] headers, const(void)[] raw_headers);
|
extern (D) int ouePointHeaders(ref const(UsbExtremeBase)[] headers, const(void)[] rawHeaders);
|
||||||
extern (D) UsbExtremeVersion oueHeadersVersion(const(void)[] headers);
|
extern (D) UsbExtremeVersion oueHeadersVersion(const(void)[] headers);
|
||||||
extern (D) int oueReadHeaders(ref usb_extreme_headers headers, const(void)[] raw_headers);
|
extern (D) int oueReadHeaders(ref UsbExtremeHeaders headers, const(void)[] rawHeaders);
|
||||||
extern (D) usb_extreme_filestat[] oueRead(usb_extreme_filestat[] filestats, const(usb_extreme_headers) headers);
|
extern (D) UsbExtremeFilestat[] oueRead(UsbExtremeFilestat[] filestats, const(UsbExtremeHeaders) headers);
|
||||||
private R[] castArray(R, T)(T[] array)
|
private R[] castArray(R, T)(T[] array)
|
||||||
{
|
{
|
||||||
auto ptr = array.ptr;
|
auto ptr = array.ptr;
|
||||||
|
30
lib/cabi.d
30
lib/cabi.d
@ -2,28 +2,28 @@ module cabi;
|
|||||||
import std.stdint;
|
import std.stdint;
|
||||||
import usbextreme;
|
import usbextreme;
|
||||||
|
|
||||||
extern(C) int is_oue(const(void)* headers, size_t headerslen) {
|
extern(C) int is_oue(const(void)* headers, size_t headersLen) {
|
||||||
return isOue(headers[0..headerslen]);
|
return isOue(headers[0..headersLen]);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern(C) UsbExtremeVersion get_version(uint8_t usbExtremeVersion) {
|
extern(C) UsbExtremeVersion get_version(uint8_t usbExtremeVersion) {
|
||||||
return getVersion(usbExtremeVersion);
|
return getVersion(usbExtremeVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern(C) int oue_num_headers(int *num_headers, const(void) *headers, size_t headerslen) {
|
extern(C) int oue_num_headers(int *numHeaders, const(void) *headers, size_t headersLen) {
|
||||||
auto result = oueNumHeaders(headers[0..headerslen]);
|
auto result = oueNumHeaders(headers[0..headersLen]);
|
||||||
*num_headers = result;
|
*numHeaders = result;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern(C) int oue_point_headers(const(usb_extreme_base)** headers, const(void)* raw_headers, size_t headerslen) {
|
extern(C) int oue_point_headers(const(UsbExtremeBase)** headers, const(void)* rawHeaders, size_t headersLen) {
|
||||||
auto len = headerslen / usb_extreme_base.sizeof;
|
auto len = headersLen / UsbExtremeBase.sizeof;
|
||||||
const(usb_extreme_base)[] headersArr = (*headers)[0..len];
|
const(UsbExtremeBase)[] headersArr = (*headers)[0..len];
|
||||||
return ouePointHeaders(headersArr, raw_headers[0..headerslen]);
|
return ouePointHeaders(headersArr, rawHeaders[0..headersLen]);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern(C) int oue_version(UsbExtremeVersion* oueVersion, const(void) *headers, size_t headerslen) {
|
extern(C) int oue_version(UsbExtremeVersion* oueVersion, const(void) *headers, size_t headersLen) {
|
||||||
auto result = oueHeadersVersion(headers[0..headerslen]);
|
auto result = oueHeadersVersion(headers[0..headersLen]);
|
||||||
|
|
||||||
if (result == UsbExtremeVersion.Unknown) {
|
if (result == UsbExtremeVersion.Unknown) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -33,11 +33,11 @@ extern(C) int oue_version(UsbExtremeVersion* oueVersion, const(void) *headers, s
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern(C) int oue_read_headers(usb_extreme_headers* headers, const(void)* raw_headers, size_t headerslen) {
|
extern(C) int oue_read_headers(UsbExtremeHeaders* headers, const(void)* rawHeaders, size_t headersLen) {
|
||||||
return oueReadHeaders(*headers, raw_headers[0..headerslen]);
|
return oueReadHeaders(*headers, rawHeaders[0..headersLen]);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern(C) int oue_read(usb_extreme_filestat* filestat, const(usb_extreme_headers) headers, int filestats_nlen) {
|
extern(C) int oue_read(UsbExtremeFilestat* filestat, const(UsbExtremeHeaders) headers, int filestatsLen) {
|
||||||
auto result = oueRead(filestat[0..filestats_nlen], headers);
|
auto result = oueRead(filestat[0..filestatsLen], headers);
|
||||||
return cast(int) result.length;
|
return cast(int) result.length;
|
||||||
}
|
}
|
||||||
|
@ -5,16 +5,16 @@ enum USBEXTREME_NAME_LENGTH = 32;
|
|||||||
enum USBEXTREME_ID_LENGTH = 15;
|
enum USBEXTREME_ID_LENGTH = 15;
|
||||||
enum USBEXTREME_NAME_EXT_LENGTH = 10;
|
enum USBEXTREME_NAME_EXT_LENGTH = 10;
|
||||||
enum USBEXTREME_MAGIC = 0x08;
|
enum USBEXTREME_MAGIC = 0x08;
|
||||||
enum USBEXTREME_HEADER_SIZE = usb_extreme_base.sizeof;
|
enum USBEXTREME_HEADER_SIZE = UsbExtremeBase.sizeof;
|
||||||
|
|
||||||
align(1) struct usb_extreme_base {
|
align(1) struct UsbExtremeBase {
|
||||||
align(1):
|
align(1):
|
||||||
uint8_t[6 + USBEXTREME_ID_LENGTH + USBEXTREME_NAME_LENGTH] empty;
|
uint8_t[6 + USBEXTREME_ID_LENGTH + USBEXTREME_NAME_LENGTH] empty;
|
||||||
uint8_t magic;
|
uint8_t magic;
|
||||||
uint8_t[10] empty2;
|
uint8_t[10] empty2;
|
||||||
}
|
}
|
||||||
|
|
||||||
align(1) struct usb_extreme_v0 {
|
align(1) struct UsbExtremeV0 {
|
||||||
align(1):
|
align(1):
|
||||||
char[USBEXTREME_NAME_LENGTH] name;
|
char[USBEXTREME_NAME_LENGTH] name;
|
||||||
char[USBEXTREME_ID_LENGTH] id;
|
char[USBEXTREME_ID_LENGTH] id;
|
||||||
@ -25,34 +25,34 @@ align(1) struct usb_extreme_v0 {
|
|||||||
uint8_t[USBEXTREME_NAME_EXT_LENGTH] empty2;
|
uint8_t[USBEXTREME_NAME_EXT_LENGTH] empty2;
|
||||||
}
|
}
|
||||||
|
|
||||||
align(1) struct usb_extreme_v1 {
|
align(1) struct UsbExtremeV1 {
|
||||||
align(1):
|
align(1):
|
||||||
char[USBEXTREME_NAME_LENGTH] name;
|
char[USBEXTREME_NAME_LENGTH] name;
|
||||||
char[USBEXTREME_ID_LENGTH] id;
|
char[USBEXTREME_ID_LENGTH] id;
|
||||||
uint8_t n_parts;
|
uint8_t n_parts;
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
uint16_t size;
|
uint16_t size;
|
||||||
uint8_t video_mode;
|
uint8_t videoMode;
|
||||||
uint8_t usb_extreme_version;
|
uint8_t usbExtremeVersion;
|
||||||
uint8_t magic;
|
uint8_t magic;
|
||||||
char[USBEXTREME_NAME_EXT_LENGTH] name_ext;
|
char[USBEXTREME_NAME_EXT_LENGTH] nameExt;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct usb_extreme_headers {
|
struct UsbExtremeHeaders {
|
||||||
const(void)* first_header;
|
const(void)* firstHeader;
|
||||||
const(usb_extreme_base)[] headers;
|
const(UsbExtremeBase)[] headers;
|
||||||
int num_headers;
|
int numHeaders;
|
||||||
size_t headerslen;
|
size_t headersLen;
|
||||||
UsbExtremeVersion oueVersion;
|
UsbExtremeVersion oueVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct usb_extreme_filestat {
|
struct UsbExtremeFilestat {
|
||||||
int offset;
|
int offset;
|
||||||
char[USBEXTREME_NAME_LENGTH + USBEXTREME_NAME_EXT_LENGTH] name;
|
char[USBEXTREME_NAME_LENGTH + USBEXTREME_NAME_EXT_LENGTH] name;
|
||||||
SCECdvdMediaType type;
|
SCECdvdMediaType type;
|
||||||
uint16_t size;
|
uint16_t size;
|
||||||
uint8_t video_mode;
|
uint8_t videoMode;
|
||||||
UsbExtremeVersion usb_extreme_version;
|
UsbExtremeVersion usbExtremeVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum UsbExtremeVersion {
|
enum UsbExtremeVersion {
|
||||||
@ -82,9 +82,9 @@ enum SCECdvdMediaType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extern(D) bool isOue(const(void)[] headers) {
|
extern(D) bool isOue(const(void)[] headers) {
|
||||||
auto headers_oeu = castArray!(const usb_extreme_base)(headers);
|
auto headersOeu = castArray!(const UsbExtremeBase)(headers);
|
||||||
|
|
||||||
foreach (header; headers_oeu) {
|
foreach (header; headersOeu) {
|
||||||
if (header.magic != USBEXTREME_MAGIC) {
|
if (header.magic != USBEXTREME_MAGIC) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -110,52 +110,52 @@ extern(D) UsbExtremeVersion getVersion(uint8_t usbExtremeVersion) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extern(D) int oueNumHeaders(const(void)[] headers) {
|
extern(D) int oueNumHeaders(const(void)[] headers) {
|
||||||
auto headers_nlen = cast(int) (castArray!(usb_extreme_base)(headers).length);
|
auto headersLen = cast(int) (castArray!(UsbExtremeBase)(headers).length);
|
||||||
|
|
||||||
if (!isOue(headers)) {
|
if (!isOue(headers)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return headers_nlen;
|
return headersLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern(D) int ouePointHeaders(ref const(usb_extreme_base)[] headers, const(void)[] raw_headers) {
|
extern(D) int ouePointHeaders(ref const(UsbExtremeBase)[] headers, const(void)[] rawHeaders) {
|
||||||
auto headers_nlen = oueNumHeaders(raw_headers);
|
auto headersLen = oueNumHeaders(rawHeaders);
|
||||||
|
|
||||||
if (headers_nlen <= 0) {
|
if (headersLen <= 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
headers = castArray!(const(usb_extreme_base))(raw_headers)[];
|
headers = castArray!(const(UsbExtremeBase))(rawHeaders)[];
|
||||||
return headers_nlen;
|
return headersLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern(D) UsbExtremeVersion oueHeadersVersion(const(void)[] headers) {
|
extern(D) UsbExtremeVersion oueHeadersVersion(const(void)[] headers) {
|
||||||
auto headers_oeu = castArray!(usb_extreme_v1)(headers);
|
auto headersOeu = castArray!(UsbExtremeV1)(headers);
|
||||||
auto first_version = UsbExtremeVersion.V0;
|
auto firstVersion = UsbExtremeVersion.V0;
|
||||||
|
|
||||||
if (!isOue(headers)) {
|
if (!isOue(headers)) {
|
||||||
return UsbExtremeVersion.Unknown;
|
return UsbExtremeVersion.Unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (i, header; headers_oeu) {
|
foreach (i, header; headersOeu) {
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
first_version = getVersion(header.usb_extreme_version);
|
firstVersion = getVersion(header.usbExtremeVersion);
|
||||||
} else {
|
} else {
|
||||||
if (first_version != getVersion(header.usb_extreme_version)) {
|
if (firstVersion != getVersion(header.usbExtremeVersion)) {
|
||||||
return UsbExtremeVersion.V0;
|
return UsbExtremeVersion.V0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return first_version;
|
return firstVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern(D) int oueReadHeaders(ref usb_extreme_headers headers, const(void)[] raw_headers) {
|
extern(D) int oueReadHeaders(ref UsbExtremeHeaders headers, const(void)[] rawHeaders) {
|
||||||
auto oueVersion = oueHeadersVersion(raw_headers);
|
auto oueVersion = oueHeadersVersion(rawHeaders);
|
||||||
auto num_headers = oueNumHeaders(raw_headers);
|
auto numHeaders = oueNumHeaders(rawHeaders);
|
||||||
|
|
||||||
if (!isOue(raw_headers)) {
|
if (!isOue(rawHeaders)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,18 +163,18 @@ extern(D) int oueReadHeaders(ref usb_extreme_headers headers, const(void)[] raw_
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto headersArr = castArray!(usb_extreme_base)(raw_headers);
|
auto headersArr = castArray!(UsbExtremeBase)(rawHeaders);
|
||||||
headers = usb_extreme_headers(raw_headers.ptr,
|
headers = UsbExtremeHeaders(rawHeaders.ptr,
|
||||||
headersArr,
|
headersArr,
|
||||||
num_headers,
|
numHeaders,
|
||||||
raw_headers.length,
|
rawHeaders.length,
|
||||||
oueVersion);
|
oueVersion);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern(D) usb_extreme_filestat[] oueRead(usb_extreme_filestat[] filestats, const(usb_extreme_headers) headers) {
|
extern(D) UsbExtremeFilestat[] oueRead(UsbExtremeFilestat[] filestats, const(UsbExtremeHeaders) headers) {
|
||||||
auto headers_full = castArray!(usb_extreme_v1)(headers.headers);
|
auto headersFull = castArray!(UsbExtremeV1)(headers.headers);
|
||||||
auto headersLength = headers_full.length;
|
auto headersLength = headersFull.length;
|
||||||
int fileStatsLength = 0;
|
int fileStatsLength = 0;
|
||||||
|
|
||||||
foreach (i, ref filestat; filestats) {
|
foreach (i, ref filestat; filestats) {
|
||||||
@ -182,23 +182,23 @@ extern(D) usb_extreme_filestat[] oueRead(usb_extreme_filestat[] filestats, const
|
|||||||
return filestats[0..i];
|
return filestats[0..i];
|
||||||
}
|
}
|
||||||
|
|
||||||
auto header = headers_full[i];
|
auto header = headersFull[i];
|
||||||
filestat.name[0..USBEXTREME_NAME_LENGTH] = header.name[0..$];
|
filestat.name[0..USBEXTREME_NAME_LENGTH] = header.name[0..$];
|
||||||
auto headerVersion = getVersion(header.usb_extreme_version);
|
auto headerVersion = getVersion(header.usbExtremeVersion);
|
||||||
uint16_t size = 0;
|
uint16_t size = 0;
|
||||||
uint8_t videoMode = 0;
|
uint8_t videoMode = 0;
|
||||||
|
|
||||||
if (headerVersion >= 1) {
|
if (headerVersion >= 1) {
|
||||||
size = header.size;
|
size = header.size;
|
||||||
videoMode = header.video_mode;
|
videoMode = header.videoMode;
|
||||||
filestat.name[USBEXTREME_NAME_LENGTH..USBEXTREME_NAME_LENGTH + USBEXTREME_NAME_EXT_LENGTH] = header.name_ext[0..$];
|
filestat.name[USBEXTREME_NAME_LENGTH..USBEXTREME_NAME_LENGTH + USBEXTREME_NAME_EXT_LENGTH] = header.nameExt[0..$];
|
||||||
}
|
}
|
||||||
|
|
||||||
filestat.size = size;
|
filestat.size = size;
|
||||||
filestat.type = cast(SCECdvdMediaType) header.type;
|
filestat.type = cast(SCECdvdMediaType) header.type;
|
||||||
filestat.offset = cast(int) i;
|
filestat.offset = cast(int) i;
|
||||||
filestat.video_mode = videoMode;
|
filestat.videoMode = videoMode;
|
||||||
filestat.usb_extreme_version = headerVersion;
|
filestat.usbExtremeVersion = headerVersion;
|
||||||
headersLength -= 1;
|
headersLength -= 1;
|
||||||
fileStatsLength += 1;
|
fileStatsLength += 1;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user