2 * Copyright 2006, Haiku. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Stephan Aßmus <superstippi@gmx.de>
9 #include "RDefExporter.h"
17 RDefExporter::RDefExporter()
23 RDefExporter::~RDefExporter()
29 RDefExporter::Export(const Icon
* icon
, BPositionIO
* stream
)
32 status_t ret
= FlatIconExporter::Export(icon
, &buffer
);
36 return _Export((const uint8
*)buffer
.Buffer(), buffer
.BufferLength(), stream
);
41 RDefExporter::MIMEType()
43 return "text/x-vnd.Be.ResourceDef";
50 RDefExporter::_Export(const uint8
* source
, size_t sourceSize
, BPositionIO
* stream
) const
54 sprintf(buffer
, "\nresource(<your resource id here>) #'VICN' array {\n");
55 size_t size
= strlen(buffer
);
57 ssize_t written
= stream
->Write(buffer
, size
);
59 return (status_t
)written
;
60 if (written
< (ssize_t
)size
)
64 const uint8
* b
= source
;
66 // print one line (32 values)
67 while (sourceSize
>= 32) {
68 sprintf(buffer
, " $\"%.2X%.2X%.2X%.2X"
75 "%.2X%.2X%.2X%.2X\"\n",
76 b
[0], b
[1], b
[2], b
[3],
77 b
[4], b
[5], b
[6], b
[7],
78 b
[8], b
[9], b
[10], b
[11],
79 b
[12], b
[13], b
[14], b
[15],
80 b
[16], b
[17], b
[18], b
[19],
81 b
[20], b
[21], b
[22], b
[23],
82 b
[24], b
[25], b
[26], b
[27],
83 b
[28], b
[29], b
[30], b
[31]);
85 size
= strlen(buffer
);
86 written
= stream
->Write(buffer
, size
);
87 if (written
!= (ssize_t
)size
) {
91 ret
= (status_t
)written
;
98 // beginning of last line
99 if (ret
>= B_OK
&& sourceSize
> 0) {
100 sprintf(buffer
, " $\"");
101 size
= strlen(buffer
);
102 written
= stream
->Write(buffer
, size
);
103 if (written
!= (ssize_t
)size
) {
107 ret
= (status_t
)written
;
110 // last line (up to 32 values)
111 bool endQuotes
= sourceSize
> 0;
112 if (ret
>= B_OK
&& sourceSize
> 0) {
113 for (size_t i
= 0; i
< sourceSize
; i
++) {
114 sprintf(buffer
, "%.2X", b
[i
]);
115 size
= strlen(buffer
);
116 written
= stream
->Write(buffer
, size
);
117 if (written
!= (ssize_t
)size
) {
121 ret
= (status_t
)written
;
128 sprintf(buffer
, endQuotes
? "\"\n};\n" : "};\n");
129 size
= strlen(buffer
);
130 written
= stream
->Write(buffer
, size
);
131 if (written
!= (ssize_t
)size
) {
135 ret
= (status_t
)written
;