Backup Apps From iPhone to iTunes (If the normal ways aren’t working)

I finally just solved an annoying problem: I had downloaded an app on my wife’s iPhone that was no longer available on the App Store (ResistorCode, by Christopher Brown), but because of iPhone sync issues was unable to transfer it to iTunes from the phone.

Back Story

So my wife got the iPhone 3G when it first came out, and along the way it was synced with multiple computers, and upgraded to iPhone OS 3.0 (then 3.1, 3.1.2 etc.). This caused it to stop being able to transfer purchased apps from the phone to iTunes or the mac.

Since I didn’t have a phone yet and was interested in some apps for when I did finally get one, there were some applications that I downloaded on her phone and figured I’d be able to move to my phone later.

Normally this wouldn’t be a big deal, since the apps can be re-downloaded from the App Store free of charge as long as you use the same account. The problem is that for whatever reason this app is no longer available on the App Store. And all the other applications (free or not) don’t work as well as this one for the tasks I need.

Solution

Wife gets new iPhone 3GS, and I take old iPhone3G…

OOOOOOOOORRRRRRRRRR

Enter PhoneView which is an OS X application that allows you to view SMS, Contact and the DCIM folder on the iPhone without any iPhone modifications (read “no jailbreaking needed”). When I loaded it up with her iPhone it contained a folder name ApplicationArchives (which is empty on my new phone btw), and appears to be leftover from some revision of iPhone OS 2.0-1. In this folder is a bunch of zip files with the application package names (ie. com.christopherbrown.resistorcode.zip), but not all apps on her phone interestingly. Downloading them and unzipping them only left me with a folder with iTunesArtwork, iTunesMetaData.plist, and a Payload folder.

Turns out that’s what in those .ipa files stored in the Mobile Applications folder by iTunes!!! And—how convenient—ipa’s are just renamed zip files! So I renamed the zip file from T4342SFMV3.com.christopherbrown.resistorcode.zip to ResistorCode.ipa and put it in ~/Music/iTunes/Mobile Applications withe the rest of the apps, and… wait… nothing’s showing up in iTunes.

Until I stumbled on this post (see message #7) and low and behold, all I had to do was double click the newly renamed ResistorCode.ipa file, and it was added to itunes and able to sync with my new iPhone 3GS!

Disclaimer

This likely only worked because we are both using the same iTunes account on computers that are both authorized on said account. The app was also a completely legitimate appstore download at the time it was purchased (though free), and is simply no longer available for download from iTunes.

This also doesn’t fundamentally solve the iPhone syncing problem with my wife’s phone, which appears to only be fixable by a factory reset, and manually syncing the apps back to the phone (you’ll find that restoring the phone after a factory reset also restores the syncing problem).

I’m going to download all the remaining apps from that ApplicationArchives folder when she gets home tonight, and at least have backups in iTunes, before we decide that it’s worth wiping out all that data from her phone (so many saved games and book lists to risk…)

Tabs and Linefeeds (Newlines) in XML driven TextFields

Man Flash can be annoying sometimes. So I’m showing some settings as a list, like
Item: value1
Item Two: value2
Item Three: value3

And the client asks if we can align the values vertically, and thinking like a programmer who likes to keep his code clean I’m thinking «Sure, that shouldn’t be a problem, I’ll just add some \t’s to the XML file and we should be all set,» but all that comes out is, “Sure, should only take a few minutes to add.”

So I add some \t’s to the XML and what does flash do with them, it prints out all literal backslashes and ts.

SO then what? Well I was being lazy and specifying xml.node not xml.node.text() to get the text values. Switching it does nothing. So then I start tracing things and looking around the Goog. Finally it becomes apparent that Flash is urlencoding the XML text in the background when processing it, and when it urldecodes it, some things are kept that shouldn’t be, like all escaped string characters that would normally not print.

Oh yeah, condenseWhite was false.

So I start with just doing a simple replace(/\\t/g, “!!!!”) to find out if I can even find the damn things, and I get no exclamation marks… or dirty words. Then a forum entry that was so buried I haven’t even found it again to link to, suggested using unescape(xml.node.text()) for a close, but ultimately unrelated problem.

To make a long story short here’s the solution:

?View Code ACTIONSCRIPT
1
2
3
	var tabs:RegExp = /\\t/g;
	var newlines:RegExp = /\\n/g;
	txt.htmlText = unescape(wagerText).replace(tabs, "\t").replace(newlines, "\n");

Go figure right?

As always if anyone has a better solution I’m all ears, or at least all comment-reading… eventually.

New Boom Box find.

On our almost bi-weekly visit to the Goodwill store nearby, I found the Best Boombox yet. Feast your eyes on this:
Panasonic SG-J500 ClosedPanasonic SG-J500 Open

That’s right, a Ghetto Blaster with a turntable!

It’s no SHARP VZ-2500, but still I only paid $7.99 for it (plus tax), and it’s even featured on Engadget. Anyway I’m working on a modular plan to add iPod functionality to it like some other boomboxes I’m working on, but not the tape adapter rout, something that connects directly to the amp IC. Details coming soon.

Oh just pick a time

So it’s a difficult problem when you’re designing a form that has a lot of time inputs (the one I’m thinking of has up to 4 including a time range). There is the usual, one time box, and an AM/PM dropdown, but that requires typing then clicking, and feels  too tedious, especially the 3rd time.

Then there is the huge dropdown of times, which isn’t too bad for just hours, with which you end up with 24 options, but when you add quarter hours you get 100 items in a huge scrolling dropdown (scrolling dropdowns in themselves can be dubious to some users).

So I did some looking around and found the following options the first of which isn’t the fastest  to use, and doesn’t require the least clicks, but was the most consistent with other elements on the page, and also seemed to have the most development behind it, and I ended up using in my current project.

  1. http://pttimeselect.sourceforge.net/example/ (I think this is the cleanest, and works the best next to the date picker, because it looks the same. though it’s not the fastest or most efficient, but I think it’s the most developed.)
  2. http://milesich.com/tpdemo/ (ok but a little overwhelming possibly to some people because of the + the done button that needs to be pressed)
  3. http://labs.perifer.se/timedatepicker/ (this is probably the simplest option, but like I said, 100 might be a pain for some users)
  4. http://haineault.com/media/jquery/ui-timepickr/page/ (while my wife used it fine on the first try, it wasn’t scientific because I didn’t give her a specific time to set.)
  5. http://www.jnathanson.com/index.cfm?page=jquery/clockpick/ClockPick (OK but a little less intuitive than timepickr)
  6. http://www.radoslavdimov.com/jquery-plugins/jquery-plugin-timepicker/ (kinda ok, like a time only version of the second option, but sideways, I’m not sure how well AM/PM works because there isn’t an example)
  7. http://keith-wood.name/timeEntry.html (neat but totally hard to use until you realize its keyboard-arrow-key driven, oops I gave it away)

I think my dream selector would actually be more like this most excellent timer widget for OS X that I use almost every day called Minutes. You’d just grab it and spin around until you have the time you want, then let go to set. Anyway when I have a project with a better budget then I’ll maybe make that version…

Using Those Old PS2 Mouses You Couldn’t Throw Out

Sorry got totally distracted by a box in the basement with some PS2 Intellimouse parts in it this weekend. I’ll have those Box2D shortcuts updated soon, promise.

Anyway if you’d like to get a PS2 Microsoft Intellimouse with wheel fully working with a current (Diecimila or newer) Arduino here’s the corrected code:

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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
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
178
179
180
181
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
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
284
285
286
287
288
289
290
291
292
293
294
295
/**
 * Code is a mix of ps2mouse from the Arduino playground
 * and mousewheel code from "a world in dk" modified to
 * work with Arduino Decimilia and 0017, and run a PS2
 * Microsoft Intellimouse.
 * 
 * Collin Reidorf collin@paperclipped.com 
 * Repaired http://blowingthroughlines.com
 
 */
 
/*
 * an arduino sketch to interface with a ps/2 mouse.
 * Also uses serial protocol to talk back to the host
 * and report what it finds.
 */
 
/*
 * Pin 5 is the mouse data pin, pin 6 is the clock pin
 * Feel free to use whatever pins are convenient.
 */
#define MDATA 5
#define MCLK 6
 
/*
 * according to some code I saw, these functions will
 * correctly set the mouse clock and data pins for
 * various conditions.
 */
void gohi(int pin)
{
	pinMode(pin, INPUT);
	digitalWrite(pin, HIGH);
}
 
void golo(int pin)
{
	pinMode(pin, OUTPUT);
	digitalWrite(pin, LOW);
}
 
/* PRECONDITION : clock is HIGH */
/* sends a single bit and returns with clock high */
void sendBit(char bit)
{
	if (bit) {
		gohi(MDATA);
	} 
	else {
		golo(MDATA);
	}
	/* wait for clock cycle */
	while (digitalRead(MCLK) == LOW)
		;
	while (digitalRead(MCLK) == HIGH)
		;
}
 
/* reads a single bit and returns with clock low */
char readBit()
{
	char tmp = 0x00;
	while (digitalRead(MCLK) == HIGH)
		;
	if (digitalRead(MDATA) == HIGH) 
		tmp = 0x01;
 
	while (digitalRead(MCLK) == LOW)
		;
 
	return tmp;
}
 
void mouse_write(char data)
{
	char i;
	char parity = 1;
 
	/* put pins in output mode */
	gohi(MDATA);
	gohi(MCLK);
	delayMicroseconds(300);
	golo(MCLK);
	delayMicroseconds(300);
	golo(MDATA);
	delayMicroseconds(10);
	/* start bit */
	gohi(MCLK);
	/* wait for mouse to take control of clock); */
	sendBit(0);
 
	/* clock is low, and we are clear to send data */
	for (i=0; i < 8; i++) {
 
		sendBit(data & 0x01);
 
		parity = parity ^ (data & 0x01); // might not need this anymore but too lazy to test...
 
		data = data >> 1;
	}  
	/* parity */
	sendBit(parity);
 
	/* stop bit */
	sendBit(1);
 
	/* wait for mouse to switch modes */
	while ((digitalRead(MCLK) == LOW) || (digitalRead(MDATA) == LOW))
		;
	/* put a hold on the incoming data. */
	golo(MCLK);
}
 
/*
 * Get a byte of data from the mouse
 */
char mouse_read(void)
{
	char data = 0x00;
	int i;
	char bit = 0x01;
 
	//	Serial.print("reading byte from mouse\n");
	/* start the clock */
	gohi(MCLK);
	gohi(MDATA);
	delayMicroseconds(50);
	readBit();
 
	// delayMicroseconds(5);  /* not sure why */ // and not evidently needed
 
	for (i=0; i < 8; i++) { // read the bits
		data = data | (readBit()<<i);
	}
 
	/* eat parity bit, which we ignore */
	readBit();
 
	/* eat stop bit */
	readBit(); 
 
	/* put a hold on the incoming data. */
	golo(MCLK);
 
	return data;
}
 
// for the mousewheel
// #define verbose // for verbose output
unsigned char msInitSequence[7]; // should go up on top when ready
 
char writeAndGetResponse(char data) {
	// #ifdef verbose
		// Serial.print("sending :	 ");
		// Serial.print((unsigned char)data, HEX);
		// Serial.print("\t");
	// #endif	
 
	mouse_write( data );
	return response();
}
 
char response() {
	char data = mouse_read();
	// #ifdef verbose
		// Serial.print("echo ");
		// Serial.print((unsigned char)data, HEX);
		// Serial.print(" from mouse\n");
	// #endif
	return data;
}
// 
void msMode() {
	// sequence for ms mode (3 button + scroll)
	// this is a entering procedure and i guess it will
	// work with other mice/ICs as its problably stadard ps2
	// And using an array were just a quick way to handle them
	msInitSequence[0] =0xF3;
	msInitSequence[1] =0xC8;
	msInitSequence[2] =0xF3;
	msInitSequence[3] =0x64;
	msInitSequence[4] =0xF3;
	msInitSequence[5] =0x50;
	msInitSequence[6] =0xF2;
 
 
	int i;
	for(i=0;i<7;i++) 
		writeAndGetResponse(msInitSequence[i]);
}
 
// end of mousewheel stuff
 
 
void showMStat(char mstat)
{
	int i;
	char bit = 0x01;
	for(i = 0; i<8; i++)
	{
		if(mstat&bit)
		{
			Serial.print("\t");
			switch(i)
			{
				case 0:
					Serial.print("L");
					break;
				case 1:
					Serial.print("R");
					break;
				case 2:
					Serial.print("M");
					break;
				case 3:
					// Serial.print(" Reserve ...\t");
					break;
				case 4:
					// Serial.print(" X data negative \t");
					break;
				case 5:
					// Serial.print("Y data negative \t");
					break;
				case 6:
					Serial.print("X data overflow");
					break;
				case 7:
					Serial.print("Y data overflow");
					break;
			}
		}
		bit = bit<<1;
	} 
}
 
void mouse_init()
{
	gohi(MCLK);
	gohi(MDATA);
	//	Serial.print("Sending reset to mouse\n");
	mouse_write(0xff);
	mouse_read();  /* ack byte */
	//	Serial.print("Read ack byte1\n");
	mouse_read();  /* blank */
	mouse_read();  /* blank */
 
	msMode(); // mousewheel code
 
	//	Serial.print("Sending remote mode code\n");
	mouse_write(0xf0);	/* remote mode */
	mouse_read();  /* ack */
	//	Serial.print("Read ack byte2\n");
 
	delayMicroseconds(100);
}
 
void setup()
{
	Serial.begin(9600);
	mouse_init();
}
 
/*
 * get a reading from the mouse and report it back to the
 * host via the serial line.
 */
void loop()
{
	char mstat;
	char mx;
	char my;
	char mz;
 
	/* get a reading from the mouse */
	writeAndGetResponse(0xEB); /* give me data! */ 
 
	mstat = mouse_read();
	mx = mouse_read();
	my = mouse_read();
	mz = mouse_read();
 
	/* send the data back up */
 
	Serial.print("\tmouse status=");
	Serial.print(mstat, BIN);
	Serial.print("\tX=");
	Serial.print(mx, DEC);
	Serial.print("\tY=");
	Serial.print(my, DEC);
	Serial.print("\tZ=");
	Serial.print(mz, DEC);
	showMStat(mstat); // print buttons that are down
	Serial.println();
	delay(20);	/* twiddle */
}

Based on code from The Arduino Playground which also shows the pinouts (where the black and white drawing is the female connector’s pintout, the pins on the mouse itself are a mirror image, like in the blurry photo below) and more code from A world in dk(decay/denmark).