Check-in [24f52edab8]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Writing of PalmOS databases or resources.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 24f52edab82cb506055d5f026707e41d04b5a9e1
User & Date: stephanie.gawroriski 2019-07-13 16:49:36
Context
2019-07-13
17:14
Write missing next record list. check-in: 7c8be614a6 user: stephanie.gawroriski tags: trunk
16:49
Writing of PalmOS databases or resources. check-in: 24f52edab8 user: stephanie.gawroriski tags: trunk
15:49
Record the epoch difference for UNIX and PalmOS (Mac). check-in: ecce1ba61d user: stephanie.gawroriski tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to bldt/libs/builder-support/cc/squirreljme/builder/support/dist/PalmOSDist.java.

11
12
13
14
15
16
17

18
19
20
21
22
23
24
..
62
63
64
65
66
67
68



69
70
71
72



73
74
75
76
77
78
79

import dev.shadowtail.palmos.PalmDatabaseAttribute;
import dev.shadowtail.palmos.PalmDatabaseBuilder;
import dev.shadowtail.palmos.PalmDatabaseType;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import net.multiphasicapps.javac.ZipCompilerOutput;

/**
 * Palm OS distribution.
 *
 * @since 2019/07/13
 */
................................................................................
		// limitation
		int numfrags = (romlen / ROM_FRAGMENT_SIZE) + 1;
		
		// Create builder for the database
		PalmDatabaseBuilder db = new PalmDatabaseBuilder(
			PalmDatabaseType.RESOURCE);
		



		// Set information on the database
		db.setName("SquirrelJME ROM");
		db.setType("mROM");
		db.setCreator("SjME");



		db.setAttributes(PalmDatabaseAttribute.BACKUP,
			PalmDatabaseAttribute.OK_TO_INSTALL_NEWER,
			PalmDatabaseAttribute.BUNDLE);
		
		// Write ROM length
		try (DataOutputStream ent = new DataOutputStream(
			db.addEntry("RlEN", 0)))







>







 







>
>
>




>
>
>







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
..
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86

import dev.shadowtail.palmos.PalmDatabaseAttribute;
import dev.shadowtail.palmos.PalmDatabaseBuilder;
import dev.shadowtail.palmos.PalmDatabaseType;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Calendar;
import net.multiphasicapps.javac.ZipCompilerOutput;

/**
 * Palm OS distribution.
 *
 * @since 2019/07/13
 */
................................................................................
		// limitation
		int numfrags = (romlen / ROM_FRAGMENT_SIZE) + 1;
		
		// Create builder for the database
		PalmDatabaseBuilder db = new PalmDatabaseBuilder(
			PalmDatabaseType.RESOURCE);
		
		// Used to set the version number
		Calendar cal = Calendar.getInstance();
		
		// Set information on the database
		db.setName("SquirrelJME ROM");
		db.setType("mROM");
		db.setCreator("SjME");
		db.setVersion(((((cal.get(Calendar.YEAR) - 2016) * 365) +
			cal.get(Calendar.DAY_OF_YEAR)) * 24) +
			cal.get(Calendar.HOUR_OF_DAY));
		db.setAttributes(PalmDatabaseAttribute.BACKUP,
			PalmDatabaseAttribute.OK_TO_INSTALL_NEWER,
			PalmDatabaseAttribute.BUNDLE);
		
		// Write ROM length
		try (DataOutputStream ent = new DataOutputStream(
			db.addEntry("RlEN", 0)))

Changes to bldt/libs/palmos-utils/dev/shadowtail/palmos/PalmDatabaseBuilder.java.

12
13
14
15
16
17
18

19
20
21
22
23
24
25
..
56
57
58
59
60
61
62
























63
64
65
66
67
68
69
...
113
114
115
116
117
118
119


























120
121
122
123
124
125
126
...
131
132
133
134
135
136
137


























138
139
140
141
142
143
144
...
167
168
169
170
171
172
173


























174
175
176
177
178
179
180
...
227
228
229
230
231
232
233

234
235
236
237
238
239
240
241
242


243







244


245



































































































import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;

import java.util.Set;

/**
 * This class is used to build PalmOS databases and resource databases.
 *
 * @since 2019/07/13
 */
................................................................................
	private String _type =
		"????";
	
	/** The name of the database. */
	private String _name =
		"Untitled";
	
























	/**
	 * Initializes the database builder.
	 *
	 * @param __type The database type.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/07/13
	 */
................................................................................
		for (PalmDatabaseAttribute attr : __a)
			if (attr != null)
				attributes.add(attr);
		
		// Return self
		return this;
	}


























	
	/**
	 * Sets the creator of the database.
	 *
	 * @param __creat The creator to use.
	 * @return {@code this}.
	 * @throws NullPointerException On null arguments.
................................................................................
	{
		if (__creat == null)
			throw new NullPointerException("NARG");
		
		this._creator = __creat;
		return this;
	}


























	
	/**
	 * Sets the name of the database.
	 *
	 * @param __name The name to use.
	 * @return {@code this}.
	 * @throws NullPointerException On null arguments.
................................................................................
	{
		if (__type == null)
			throw new NullPointerException("NARG");
		
		this._type = __type;
		return this;
	}


























	
	/**
	 * Returns the byte array representing the database.
	 *
	 * @return The byte array of the database.
	 * @since 2019/07/13
	 */
................................................................................
		int attrs = 0;
		for (PalmDatabaseAttribute attr : this._attributes)
			attrs |= attr.bit;
		
		// Make sure the attribute flag is always correct because if it was
		// specified it would make the database not valid to be handled
		PalmDatabaseType dbtype = this.dbtype;

		if (dbtype == PalmDatabaseType.RESOURCE)
			attrs |= PalmDatabaseAttribute.RESOURCE_DATABASE.bit;
		else
			attrs &= ~PalmDatabaseAttribute.RESOURCE_DATABASE.bit;
		
		// Write attributes
		dos.writeShort(attrs);
		
		throw new todo.TODO();


	}







}













































































































>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
|







<
>
>
|
>
>
>
>
>
>
>
|
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
..
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
...
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
...
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
...
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
...
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345

346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;

/**
 * This class is used to build PalmOS databases and resource databases.
 *
 * @since 2019/07/13
 */
................................................................................
	private String _type =
		"????";
	
	/** The name of the database. */
	private String _name =
		"Untitled";
	
	/** Creation time. */
	private long _createtime =
		System.currentTimeMillis();
	
	/** Modification time */
	private long _modtime =
		this._createtime;
	
	/** Backup time. */
	private long _backuptime =
		0;
	
	/** Modification number. */
	private int _modcount =
		0;
	
	/** The version. */
	private int _version =
		0;
	
	/** Unique ID seed. */
	private int _uniqueid =
		new Random(this._createtime).nextInt();
	
	/**
	 * Initializes the database builder.
	 *
	 * @param __type The database type.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/07/13
	 */
................................................................................
		for (PalmDatabaseAttribute attr : __a)
			if (attr != null)
				attributes.add(attr);
		
		// Return self
		return this;
	}
	
	/**
	 * Sets the backup time.
	 *
	 * @param __jt Java milliseconds time.
	 * @return {@code this}.
	 * @since 2019/07/13
	 */
	public final PalmDatabaseBuilder setBackupTime(long __jt)
	{
		this._backuptime = __jt;
		return this;
	}
	
	/**
	 * Sets the creation time.
	 *
	 * @param __jt Java milliseconds time.
	 * @return {@code this}.
	 * @since 2019/07/13
	 */
	public final PalmDatabaseBuilder setCreateTime(long __jt)
	{
		this._createtime = __jt;
		return this;
	}
	
	/**
	 * Sets the creator of the database.
	 *
	 * @param __creat The creator to use.
	 * @return {@code this}.
	 * @throws NullPointerException On null arguments.
................................................................................
	{
		if (__creat == null)
			throw new NullPointerException("NARG");
		
		this._creator = __creat;
		return this;
	}
	
	/**
	 * Sets the modification count.
	 *
	 * @param __c The count to use.
	 * @return {@code this}.
	 * @since 2019/07/13
	 */
	public final PalmDatabaseBuilder setModificationCount(int __c)
	{
		this._modcount = __c;
		return this;
	}
	
	/**
	 * Sets the modification time.
	 *
	 * @param __jt Java milliseconds time.
	 * @return {@code this}.
	 * @since 2019/07/13
	 */
	public final PalmDatabaseBuilder setModificationTime(long __jt)
	{
		this._modtime = __jt;
		return this;
	}
	
	/**
	 * Sets the name of the database.
	 *
	 * @param __name The name to use.
	 * @return {@code this}.
	 * @throws NullPointerException On null arguments.
................................................................................
	{
		if (__type == null)
			throw new NullPointerException("NARG");
		
		this._type = __type;
		return this;
	}
	
	/**
	 * Sets the unique database ID.
	 *
	 * @param __id The database ID.
	 * @return {@code this}.
	 * @since 2019/07/13
	 */
	public final PalmDatabaseBuilder setUniqueId(int __id)
	{
		this._uniqueid = __id;
		return this;
	}
	
	/**
	 * Sets the version number.
	 *
	 * @param __v The version number.
	 * @return {@code this}.
	 * @since 2019/07/13
	 */
	public final PalmDatabaseBuilder setVersion(int __v)
	{
		this._version = __v;
		return this;
	}
	
	/**
	 * Returns the byte array representing the database.
	 *
	 * @return The byte array of the database.
	 * @since 2019/07/13
	 */
................................................................................
		int attrs = 0;
		for (PalmDatabaseAttribute attr : this._attributes)
			attrs |= attr.bit;
		
		// Make sure the attribute flag is always correct because if it was
		// specified it would make the database not valid to be handled
		PalmDatabaseType dbtype = this.dbtype;
		boolean isrc;
		if ((isrc = (dbtype == PalmDatabaseType.RESOURCE)))
			attrs |= PalmDatabaseAttribute.RESOURCE_DATABASE.bit;
		else
			attrs &= ~PalmDatabaseAttribute.RESOURCE_DATABASE.bit;
		
		// Write attributes
		dos.writeShort(attrs);
		

		// Write version
		dos.writeShort(this._version);
		
		// Creation/Modification/Backup Time (In Mac OS epoch seconds)
		dos.writeInt(
			(int)((this._createtime + _EPOCH_DIFF_MILLISECONDS) / 1000L));
		dos.writeInt(
			(int)((this._modtime + _EPOCH_DIFF_MILLISECONDS) / 1000L));
		dos.writeInt(
			(int)((this._backuptime + _EPOCH_DIFF_MILLISECONDS) / 1000L));
		
		// Modification count
		dos.writeInt(this._modcount);
		
		// Application Info
		dos.writeInt(0);
		
		// Sorting info
		dos.writeInt(0);
		
		// Type
		dos.writeInt(PalmDatabaseBuilder.__fourToInt(this._type));
		
		// Creator
		dos.writeInt(PalmDatabaseBuilder.__fourToInt(this._creator));
		
		// Unique ID
		dos.writeInt(this._uniqueid);
		
		// Need to work with records now
		List<PalmRecord> records = this._records;
		int numrecords = records.size();
		
		// Write record count
		dos.writeShort(numrecords);
		
		// Determine the base offset for entry data
		int offset = 78 + ((isrc ? 10 : 8) * numrecords);
		
		// Write table data for records
		for (int i = 0; i < numrecords; i++)
		{
			PalmRecord pr = records.get(i);
			
			// Resource entry
			if (isrc)
			{
				// Type
				dos.writeInt(PalmDatabaseBuilder.__fourToInt(pr.type));
				
				// ID
				dos.writeInt(pr.id);
				
				// Offset
				dos.writeInt(offset);
			}
			
			// Database entry
			else
			{
				// Offset
				dos.writeInt(offset);
				
				// No attributes
				dos.write(0);
				
				// Unique ID (padding)
				dos.write(0);
				dos.write(0);
				dos.write(0);
			}
			
			// Offset is increased by length
			offset += pr.length;
		}
		
		// Write all records
		for (int i = 0; i < numrecords; i++)
			dos.write(records.get(i)._data);
	}
	
	/**
	 * Converts a four string to an integer.
	 *
	 * @param __four The string to convert.
	 * @return The resulting value.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/07/13
	 */
	private static final int __fourToInt(String __four)
		throws NullPointerException
	{
		if (__four == null)
			throw new NullPointerException("NARG");
		
		// There must be at least four characters
		String use = __four;
		if (__four.length() < 4)
		{
			StringBuilder sb = new StringBuilder();
			sb.append(__four);
			sb.setLength(4);
			use = sb.toString();
		}
		
		// Convert
		return ((__four.charAt(0) & 0xFF) << 24) |
			((__four.charAt(1) & 0xFF) << 16) |
			((__four.charAt(2) & 0xFF) << 8) |
			((__four.charAt(3) & 0xFF));
	}
}