forked from phildow/Journler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJournalUpgradeController.m
2256 lines (1771 loc) · 81.4 KB
/
JournalUpgradeController.m
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
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
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions
and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or other materials provided with the
distribution.
* Neither the name of the author nor the names of its contributors may be used to endorse or
promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// Basically, you can use the code in your free, commercial, private and public projects
// as long as you include the above notice and attribute the code to Philip Dow / Sprouted
// If you use this code in an app send me a note. I'd love to know how the code is used.
// Please also note that this copyright does not supersede any other copyrights applicable to
// open source code used herein. While explicit credit has been given in the Journler about box,
// it may be lacking in some instances in the source code. I will remedy this in future commits,
// and if you notice any please point them out.
#import "JournalUpgradeController.h"
#import "JournlerApplicationDelegate.h"
#import "BlogPref.h"
#import "JournlerEntry.h"
#import "JournlerJournal.h"
#import "JournlerCollection.h"
#import "JournlerResource.h"
#import "JournlerSearchManager.h"
#import "PDSingletons.h"
#import "QTInstallController.h"
#import "Definitions.h"
#import "NSString+JournlerAdditions.h"
#import "NSAlert+JournlerAdditions.h"
#import "NSURL+JournlerAdditions.h"
#import <SproutedUtilities/SproutedUtilities.h>
#import <SproutedInterface/SproutedInterface.h>
/*
#import "ZipUtilities.h"
#import "PDGradientView.h"
#import "NSWorkspace_PDCategories.h"
#import "NSString+PDStringAdditions.h"
#import "NSUserDefaults+PDDefaultsAdditions.h"
#import "AGKeychain.h"
*/
//#import "JUtility.h"
typedef enum
{
kJNoErr = 0,
kJNoCSMHandle,
kJKeyFailure
}JUpgradeErrors;
static NSString *kLogFilepath = @"1.1 to 2.5 Upgrade Log.txt";
static NSString *kLogFilepath210 = @"2.0 to 2.5 Upgrade Log.txt";
static NSString *kJournlerABFileUTI = @"com.phildow.journler.jaduid";
static NSString *kJournlerABFileExtension = @"jaduid";
@implementation JournalUpgradeController
- (id) init
{
if ( self = [self initWithWindowNibName:@"JournalUpgrade"] )
{
[self loadWindow];
}
return self;
}
- (void) windowDidLoad
{
NSInteger borders[4] = {0,0,0,0};
[container210 setBorders:borders];
[container210 setBordered:NO];
[progressIndicator210 setUsesThreadedAnimation:YES];
}
- (void) dealloc
{
[super dealloc];
}
#pragma mark -
#pragma mark 1.17 -> 2.5 upgrade
- (void) run117To210Upgrade:(JournlerJournal*)journal
{
_journal = journal;
upgradeMode = 0;
session210 = [NSApp beginModalSessionForWindow:[self window]];
[[self window] display];
[NSApp runModalSession:session210];
NSInteger i;
NSInteger lastFolderTag = 0;
NSInteger lastEntryTag = 0;
NSInteger serious_error = 0;
//BOOL index_entries = YES;
NSString *pname;
NSArray *allFiles;
NSString *endMessage;
entriesDictionary = [NSMutableDictionary dictionary];
foldersDictionary = [NSMutableDictionary dictionary];
NSMutableArray *journalEntries = [NSMutableArray array];
NSMutableArray *journalFolders = [NSMutableArray array];
NSMutableArray *journalBlogs = [NSMutableArray array];
log117 = [[NSMutableString alloc] init];
NSString *upgradeLogPath = [[_journal journalPath] stringByAppendingPathComponent:kLogFilepath];
NSString *backupDir = [[[_journal journalPath]
stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Journler Backup"];
NSString *backupPath = [backupDir stringByAppendingPathComponent:@"v1.1 to v2.5 Backup.zip"];
NSFileManager *fm = [NSFileManager defaultManager];
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
NSFontManager *fontM = [NSFontManager sharedFontManager];
//CSSM_KEY cdsaKey;
//CSSM_HANDLE cssmHandle;
// back up the journal
// -----------------------------------------------------------------
[progressIndicator210 setIndeterminate:YES];
[progressIndicator210 startAnimation:self];
[progressText210 setStringValue:NSLocalizedStringFromTable(@"backing up", @"UpgradeController", @"")];
[NSApp runModalSession:session210];
if ( ![fm fileExistsAtPath:backupDir] )
{
if ( ![fm createDirectoryAtPath:backupDir attributes:nil] )
{
// Unable to backup the journler directory, ask the user if he/she would like to continue
[log117 appendString:[NSString stringWithFormat:
@"** 2.5 Upgrade cannot backup journal: Unable to create backup directory at %@ **\n", backupPath]];
// discontinue the upgrade
if ( [[NSAlert upgradeCreateBackupDirectoryFailure] runModal] == NSAlertFirstButtonReturn )
{
NSError *error = nil;
if ( ![log117 writeToFile:upgradeLogPath atomically:NO encoding:NSUnicodeStringEncoding error:&error] )
NSLog(@"%s - unable to write upgrade log to %@, error %@", __PRETTY_FUNCTION__, upgradeLogPath, error);
[log117 release];
[self quit210Upgrade:self];
}
}
}
if ( [fm fileExistsAtPath:backupDir] )
{
// ensure the backup is not overwriting a previous save
backupPath = [backupPath pathWithoutOverwritingSelf];
//if ( ![JUtility zip:[_journal journalPath] toFile:backupPath] )
if ( ![ZipUtilities zip:[_journal journalPath] toFile:backupPath] )
{
// if the zip failed
[log117 appendString:[NSString stringWithFormat:@"** 2.5 Upgrade cannot backup journal: Unable to zip journal to %@ **\n", backupPath]];
// discontinue the upgrade
if ( [[NSAlert upgradeBackupOldEntriesFailure] runModal] == NSAlertFirstButtonReturn )
{
NSError *error = nil;
if ( ![log117 writeToFile:upgradeLogPath atomically:NO encoding:NSUnicodeStringEncoding error:&error] )
NSLog(@"%s - unable to write upgrade log to %@, error %@", __PRETTY_FUNCTION__, upgradeLogPath, error);
[log117 release];
[self quit210Upgrade:self];
}
}
}
// before doing anything, check if the user's journal is encrypted and let them know that encryption is no longer supported
BOOL check_for_encryption = ( [ud integerForKey:@"Encryption"] != 0 );
if ( check_for_encryption )
{
[[NSAlert upgradeEncryptionNoLongerSupported] runModal];
[self quit210Upgrade:self];
}
// check on the journal's identification and assign one if necessary
// ----------------------------------------------------------
if ( ![[_journal properties] objectForKey:PDJournalIdentifier] )
{
[log117 appendString:@"No journal identifier, assigning new ID.\n"];
[_journal setIdentifier:[NSNumber numberWithDouble:[NSDate timeIntervalSinceReferenceDate]]];
}
// create the resources directory
if ( ![fm fileExistsAtPath:[_journal resourcesPath]] && ![fm createDirectoryAtPath:[_journal resourcesPath] attributes:nil] )
{
// critical error
[log117 appendString:@"** Unable to create a resources directory **\n"];
[[NSAlert upgradeCreateResourcesFolderFailure] runModal];
NSError *error = nil;
if ( ![log117 writeToFile:upgradeLogPath atomically:NO encoding:NSUnicodeStringEncoding error:&error] )
NSLog(@"%s - unable to write upgrade log to %@, error %@", __PRETTY_FUNCTION__, upgradeLogPath, error);
[log117 release];
[self quit210Upgrade:self];
}
// convert the collections
// -----------------------------------------------------------------
NSString *collectionsPath = [_journal collectionsPath];
if ( ![fm fileExistsAtPath:collectionsPath] )
{
if ( ![fm createDirectoryAtPath:collectionsPath attributes:nil] )
{
// critical error
[log117 appendString:[NSString stringWithFormat:@"**2.5 Upgrade cannot create a collections folder at %@\n**", collectionsPath]];
[[NSAlert upgradeCreateCollectionsFolderFailure] runModal];
NSError *error = nil;
if ( ![log117 writeToFile:upgradeLogPath atomically:NO encoding:NSUnicodeStringEncoding error:&error] )
NSLog(@"%s - unable to write upgrade log to %@, error %@", __PRETTY_FUNCTION__, upgradeLogPath, error);
[log117 release];
[self quit210Upgrade:self];
}
}
// disable threaded indexing
//[[_journal searchManager] setIndexesOnSeparateThread:NO];
NSArray *oldCollectionDics = [[_journal properties] objectForKey:PDJournalCollections];
[log117 appendString:@"Upgrading collections from 1.1 to 2.5 format.\n"];
[progressText210 setStringValue:NSLocalizedStringFromTable(@"converting collections", @"UpgradeController", @"")];
[progressIndicator210 stopAnimation:self];
[progressIndicator210 setIndeterminate:NO];
[progressIndicator210 setMinValue:0.0];
[progressIndicator210 setMaxValue:[oldCollectionDics count]];
[progressIndicator210 setDoubleValue:0.0];
for ( i = 0; i < [oldCollectionDics count]; i++ )
{
NSAutoreleasePool *innerPool = [[NSAutoreleasePool alloc] init];
JournlerCollection *aNode = [[[JournlerCollection alloc] initWithProperties:[oldCollectionDics objectAtIndex:i]] autorelease];
// explicity set the parent to root
[aNode setParentID:[NSNumber numberWithInteger:-1]];
// set the entry ids to what is in the entry field -- already tags
[aNode setEntryIDs:[[aNode properties] objectForKey:PDCollectionEntries]];
// explicity set the children ids to none
[aNode setChildrenIDs:[NSArray array]];
// set the journal id and version
[aNode setVersion:[NSNumber numberWithInteger:250]];
[aNode setJournalID:[_journal identifier]];
// establish a relationship to the journal
[aNode setJournal:_journal];
// convert the type to a typeID
NSString *oldType = [aNode pureType];
if ( [oldType isEqualToString:PDCollectionTypeFolder] )
[aNode setTypeID:[NSNumber numberWithInteger:PDCollectionTypeIDFolder]];
else if ( [oldType isEqualToString:PDCollectionTypeSmart] )
[aNode setTypeID:[NSNumber numberWithInteger:PDCollectionTypeIDSmart]];
else if ( [oldType isEqualToString:PDCollectionTypeLibrary] )
[aNode setTypeID:[NSNumber numberWithInteger:PDCollectionTypeIDLibrary]];
else if ( [oldType isEqualToString:PDCollectionTypeTrash] )
[aNode setTypeID:[NSNumber numberWithInteger:PDCollectionTypeIDTrash]];
else
[aNode setTypeID:[NSNumber numberWithInteger:PDCollectionTypeIDFolder]];
// update the image to a standard value
[aNode determineIcon];
// remove old items from the collection that are not needed and upgrade the internal variables
[aNode clearOldProperties];
[aNode updateForTwoZero];
// update last tag and count
if ( lastFolderTag < [[aNode tagID] integerValue] )
lastFolderTag = [[aNode tagID] integerValue];
// store in the array for sorting and ordering
[journalFolders addObject:aNode];
// store in the dictionary for link processing
[foldersDictionary setObject:aNode forKey:[aNode valueForKey:@"tagID"]];
// autorelease and run the modal session
[progressIndicator210 incrementBy:1.0];
[NSApp runModalSession:session210];
[innerPool release];
}
// sort the collections
// -----------------------------------------------------------------
NSArray *defaultSort = [[[NSArray alloc] initWithObjects:
[[[NSSortDescriptor alloc]
initWithKey:PDCollectionTypeID ascending:YES selector:@selector(compare:)] autorelease],
[[[NSSortDescriptor alloc]
initWithKey:PDCollectionTitle ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)] autorelease],
nil] autorelease];
[journalFolders sortUsingDescriptors:defaultSort];
[progressText210 setStringValue:NSLocalizedStringFromTable(@"saving collections", @"UpgradeController", @"")];
[progressIndicator210 setMinValue:0.0];
[progressIndicator210 setMaxValue:[oldCollectionDics count]];
[progressIndicator210 setDoubleValue:0.0];
for ( i = 0; i < [journalFolders count]; i++ )
{
NSAutoreleasePool *innerPool = [[NSAutoreleasePool alloc] init];
JournlerCollection *aNode = [journalFolders objectAtIndex:i];
// set the index on the node, now ordered in its proper place
[aNode setValue:[NSNumber numberWithInteger:i] forKey:@"index"];
// autorelease and run the modal session
[progressIndicator210 incrementBy:1.0];
[NSApp runModalSession:session210];
[innerPool release];
}
// reset the search index and disable during upgrade
// -----------------------------------------------------------------
[[_journal searchManager] closeIndex];
[[_journal searchManager] deleteIndexAtPath:[_journal journalPath]];
[_journal setSaveEntryOptions:kEntrySaveDoNotIndex|kEntrySaveDoNotCollect];
/*
[log117 appendString:@"Rebuilding search index\n"];
if ( [[_journal searchManager] createIndexAtPath:[_journal journalPath]] && [[_journal searchManager] loadIndexAtPath:[_journal journalPath]] )
{
index_entries = YES;
[log117 appendString:@"Successfully reset search index\n"];
}
else
{
index_entries = NO;
[log117 appendString:@"**Unable to reset search index**\n"];
[[NSAlert upgradeRecreateSearchIndexFailure] runModal];
}
*/
// load the entries, decrypting them if necessary
// -----------------------------------------------------------------
[log117 appendString:@"Upgrading entries from 1.1 to 2.5 format.\n"];
// DIRECTORY_ENUMERATION
NSEnumerator *direnum;
allFiles = [fm directoryContentsAtPath:[_journal entriesPath]];
direnum = [allFiles objectEnumerator];
[progressText210 setStringValue:NSLocalizedStringFromTable(@"converting entries", @"UpgradeController", @"")];
[progressIndicator210 setMinValue:0.0];
[progressIndicator210 setMaxValue:[allFiles count]-2];
[progressIndicator210 setDoubleValue:0.0];
while ( pname = [direnum nextObject] )
{
if ([[pname pathExtension] isEqualToString:@"jobj"])
{
NSAutoreleasePool *innerPool = [[NSAutoreleasePool alloc] init];
JournlerEntry *anEntry;
NSString *entryPath = [[_journal entriesPath] stringByAppendingPathComponent:pname];
// load the entry depending on the presence of encrypted entries
//if ( check_for_encryption )
// anEntry = [[[JournlerEntry alloc] initWithEncryptedPath:entryPath CSSMHandle:&cssmHandle CSSMKey:&cdsaKey] autorelease];
//else
anEntry = [[[JournlerEntry alloc] initWithPath:entryPath] autorelease];
if ( anEntry != nil )
{
// upgrade the entry to 2.5
if ( [anEntry performOneTwoMaintenance:&log117] )
{
[log117 appendString:[NSString stringWithFormat:@"%@ successfully upgraded\n", [anEntry tagID]]];
// note the cal date modified
NSCalendarDate *dateModified = [[[anEntry valueForKey:@"calDateModified"] retain] autorelease];
// assign the entry to this journal, establish a relationship to the journal
[anEntry setJournalID:[_journal identifier]];
[anEntry setJournal:_journal];
// upgrade the entry's internal format
[anEntry setValue:[NSNumber numberWithInteger:250] forKey:@"version"];
// perform maintenance on the entry (remove deprecated properties)
[anEntry perform210Maintenance];
// set the caldate modified back
[anEntry setValue:dateModified forKey:@"calDateModified"];
// add the entry to a temp array
[journalEntries addObject:anEntry];
// store in the dictionary for link processing
[entriesDictionary setObject:anEntry forKey:[anEntry valueForKey:@"tagID"]];
// increment the tag and count
if ( lastEntryTag < [[anEntry tagID] integerValue] )
lastEntryTag = [[anEntry tagID] integerValue];
}
else
{
serious_error++;
[log117 appendString:[NSString stringWithFormat:@"** Could not upgrade %@ **\n", [anEntry tagID]]];
}
}
else
{
serious_error++;
[log117 appendString:[NSString stringWithFormat:@"** Unable to read entry for upgrade at path %@ **\n", entryPath]];
}
// delete the old entry no matter what
if ( ![fm removeFileAtPath:entryPath handler:self] )
{
// error deleting the old file
[log117 appendString:[NSString stringWithFormat:@"** Unable to delete old format entry at %@ **\n", entryPath]];
}
// autorelease pool
[innerPool release];
}
// run the modal session
[progressIndicator210 incrementBy:1.0];
[NSApp runModalSession:session210];
}
// convert the links in the entry
[progressText210 setStringValue:NSLocalizedStringFromTable(@"processing entries", @"UpgradeController", @"")];
[progressIndicator210 setMinValue:0.0];
[progressIndicator210 setMaxValue:[journalEntries count]];
[progressIndicator210 setDoubleValue:0.0];
JournlerEntry *entryForLinks;
direnum = [journalEntries objectEnumerator];
while ( entryForLinks = [direnum nextObject] )
{
// note the cal date modified
NSCalendarDate *dateModified = [[[entryForLinks valueForKey:@"calDateModified"] retain] autorelease];
// process the entry's links
[self processResourcesLinksForEntry117To210:entryForLinks];
// reset the date modified
[entryForLinks setDateModified:dateModified];
// write the entry back to disk
if ( ![_journal saveEntry:entryForLinks] )
{
// error writing the file to disk
[log117 appendString:[NSString stringWithFormat:@"** Unable to write new entry %@ **\n", [entryForLinks tagID]]];
}
// run the modal session
[progressIndicator210 incrementBy:1.0];
[NSApp runModalSession:session210];
}
//
// process the entry ids into actual objects and save the folders
for ( i = 0; i < [journalFolders count]; i++ )
{
JournlerCollection *aFolder = [journalFolders objectAtIndex:i];
NSArray *actualEntries = [self entriesForTagIDs:[aFolder entryIDs]];
[aFolder setEntries:actualEntries];
// save the collection to disk and note
if ( [_journal saveCollection:aFolder] )
[log117 appendString:[NSString stringWithFormat:@"%@ collection successfully upgraded\n", [aFolder tagID]]];
else
{
serious_error++;
[log117 appendString:[NSString stringWithFormat:@"** Could not upgrade collection %@ **\n", [aFolder tagID]]];
}
}
// convert and removed unneeded preferences
// -----------------------------------------------------------------
// convert the preferences blogs to actual blog preferences and save them in journler
[progressText210 setStringValue:NSLocalizedStringFromTable(@"updating preferences", @"UpgradeController", @"")];
[progressIndicator210 setIndeterminate:YES];
[progressIndicator210 startAnimation:self];
if ( ![[NSFileManager defaultManager] createDirectoryAtPath:[_journal blogsPath] attributes:nil] )
{
[log117 appendString:@"** Unable to create a blogs directory - you're blog preferences have been reset **\n"];
}
else
{
// try to load the blogs from preferences, but if they aren't there, go for the journal
NSArray *blog_preferences = [ud arrayForKey:@"Journler Blog Preferences"];
if ( blog_preferences == nil || [blog_preferences count] == 0 )
blog_preferences = [[_journal properties] objectForKey:@"Blogs"];
if ( blog_preferences && [blog_preferences count] != 0 )
{
NSInteger b;
for ( b = 0; b < [blog_preferences count]; b++ )
{
NSAutoreleasePool *innerPool = [[NSAutoreleasePool alloc] init];
BlogPref *aBlog = [[[BlogPref alloc] initWithProperties:[blog_preferences objectAtIndex:b]] autorelease];
if ( aBlog == nil )
continue;
// give the blog a unique id
[aBlog setValue:[NSNumber numberWithInteger:b] forKey:@"tagID"];
// write the blog to disk
if ( ![_journal saveBlog:aBlog] )
{
serious_error++;
[log117 appendString:[NSString stringWithFormat:
@"** Unable to save blog preference %@, the preferences has been reset **\n", [aBlog name]]];
}
// add the blog to the master list
[journalBlogs addObject:aBlog];
// autorelease pool
[innerPool release];
}
}
// run the modal session
[NSApp runModalSession:session210];
}
[ud removeObjectForKey:@"Journler Blog Preferences"];
// copy the wordlist if available to the user's support directory - that way the user can make changes without damaging original
NSString *wordlistDestination = [[_journal journalPath] stringByAppendingPathComponent:PDJournalWordListLoc];
NSString *wordlistSource = [[NSBundle mainBundle] pathForResource:@"AutoCorrectWordPairs" ofType:@"csv"];
if ( wordlistSource != nil && wordlistDestination != nil )
{
if ( ![[NSFileManager defaultManager] copyPath:wordlistSource toPath:wordlistDestination handler:self] )
{
[log210 appendFormat:@"%s - unable to copy wordlist from %@ to %@\n\n", __PRETTY_FUNCTION__, wordlistSource, wordlistDestination];
[ud setBool:NO forKey:@"EntryTextAutoCorrectSpelling"];
[ud setBool:NO forKey:@"EntryTextAutoCorrectSpellingUseWordList"];
}
else
{
[ud setBool:YES forKey:@"EntryTextAutoCorrectSpelling"];
[ud setBool:YES forKey:@"EntryTextAutoCorrectSpellingUseWordList"];
}
}
// update the user's preferences
[ud setBool:YES forKey:@"EntryExportIncludeHeader"];
[ud setBool:YES forKey:@"EntryExportSetCreationDate"];
[ud setBool:YES forKey:@"EntryExportSetModificationDate"];
[ud setBool:NO forKey:@"ImportPreserveDateModified"];
[ud setBool:NO forKey:@"EntryImportSetDefaultResource"];
[ud setBool:YES forKey:@"SourceListShowsEntryCount"];
[ud setBool:YES forKey:@"BlogsUseAdvancedHTMLGeneration"];
[ud setBool:YES forKey:@"ExportsUseAdvancedHTMLGeneration"];
[ud setBool:YES forKey:@"CopyingUseAdvancedHTMLGeneration"];
[ud setObject:@"font, min-height" forKey:@"BlogsNoAttributeList"];
[ud setObject:[NSString string] forKey:@"ExportsNoAttributeList"];
[ud setObject:[NSString string] forKey:@"CopyingNoAttributeList"];
[ud setBool:YES forKey:@"WebViewFindIgnoreCase"];
[ud setBool:NO forKey:@"SearchSpaceMeansOr"];
[ud setBool:NO forKey:@"NewEntryImportNewWindow"];
[ud setBool:NO forKey:@"EditDatesWithGraphicalInterface"];
[ud setBool:NO forKey:@"NewEntryWithDueDate"];
[ud setBool:YES forKey:@"MainWindowBookmarksVisible"];
[ud setBool:NO forKey:@"MainWindowTabsAlwaysVisible"];
//[ud setBool:YES forKey:@"SearchIncludesEntries"];
//[ud setBool:YES forKey:@"SearchIncludesResources"];
[ud setBool:YES forKey:@"SearchMediaByDefault"];
[ud setBool:YES forKey:@"EntryTextUseSmartQuotes"];
[ud setBool:YES forKey:@"EntryTextShowWordCount"];
[ud setBool:YES forKey:@"EntryTextEnableSpellChecking"];
[ud setBool:YES forKey:@"EntryTextRecognizeWikiLinks"];
[ud setBool:YES forKey:@"EntryTextRecognizeURLs"];
[ud setBool:NO forKey:@"EntryTextAutoCorrectSpellingUseBuiltIn"];
[ud setInteger:100 forKey:@"EntryTextDefaultZoom"];
[ud setInteger:100 forKey:@"EntryTextFullscreenZoom"];
[ud setInteger:0 forKey:@"EntryTextHorizontalInset"];
[ud setInteger:100 forKey:@"EntryTextHorizontalInsetFullscreen"];
[ud setInteger:80 forKey:@"PhotoViewPhotoSize"];
[ud setBool:YES forKey:@"EntryTextLinkUnderlined"];
[ud setColor:[NSColor blueColor] forKey:@"EntryTextLinkColor"];
[ud setBool:YES forKey:@"ResourceTableShowFolders"];
[ud setBool:YES forKey:@"ResourceTableShowJournlerLinks"];
[ud setBool:NO forKey:@"ResourceTableCollapseDocuments"];
[ud setBool:NO forKey:@"ResourceTableArrangedCollapsedDocumentsByKind"];
[ud setColor:[NSColor whiteColor] forKey:@"HeaderBackgroundColor"];
[ud setColor:[NSColor whiteColor] forKey:@"EntryBackgroundColor"];
[ud setColor:[NSColor colorWithCalibratedWhite:0.75 alpha:1.0] forKey:@"HeaderLabelColor"];
[ud setColor:[NSColor colorWithCalibratedWhite:0.00 alpha:1.0] forKey:@"HeaderTextColor"];
[ud setFont:[NSFont controlContentFontOfSize:11] forKey:@"BrowserTableFont"];
[ud setFont:[NSFont controlContentFontOfSize:11] forKey:@"FoldersTableFont"];
[ud setFont:[NSFont controlContentFontOfSize:11] forKey:@"ReferencesTableFont"];
[ud setInteger:0 forKey:@"DefaultSnapshotFormat"];
[ud setInteger:0 forKey:@"DefaultAudioCodec"];
[ud removeObjectForKey:@"Lockout Enabled"];
// convert font faces and sizes to actual font objects
// ------------------------------------------------------------------------------------
NSString *fontName;
NSNumber *fontSize;
NSData *fontData;
NSFont *tempFont;
tempFont = [NSFont systemFontOfSize:14.0];
fontName = [ud objectForKey:@"Journler Default Font"];
tempFont = [fontM convertFont:tempFont toFace:( fontName ? fontName : [[NSFont systemFontOfSize:14.0] fontName] )];
fontSize = [ud objectForKey:@"Text Font Size"];
tempFont = [fontM convertFont:tempFont toSize:( fontSize ? [fontSize floatValue] : 13.0 )];
fontData = [NSArchiver archivedDataWithRootObject:tempFont];
if ( fontData ) [ud setObject:fontData forKey:@"DefaultEntryFont"];
else [log117 appendString:@"Unable to set the default entry text font.\n"];
// remove old font data
[ud removeObjectForKey:@"Datestamp Font"];
[ud removeObjectForKey:@"Datestamp Font Size"];
[ud removeObjectForKey:@"Title Font"];
[ud removeObjectForKey:@"Title Font Size"];
[ud removeObjectForKey:@"Category Font"];
[ud removeObjectForKey:@"Category Font Size"];
[ud removeObjectForKey:@"Keywords Font"];
[ud removeObjectForKey:@"Keywords Font Size"];
[ud removeObjectForKey:@"Journler Default Font"];
[ud removeObjectForKey:@"Text Font Size"];
// reset the toolbar
[ud removeObjectForKey:@"NSToolbar Configuration My Document Toolbar Identifier"];
[ud removeObjectForKey:@"NSToolbar Configuration Entry Window Toolbar"];
[ud removeObjectForKey:@"NSToolbar Configuration Blog Center Toolbar ID"];
// make sure the highlight colors are available
if ( ![ud fontForKey:@"highlightYellow"] )
{
[ud setColor:[NSColor yellowColor] forKey:@"highlightYellow"];
[ud setColor:[NSColor blueColor] forKey:@"highlightBlue"];
[ud setColor:[NSColor greenColor] forKey:@"highlightGreen"];
[ud setColor:[NSColor orangeColor] forKey:@"highlightOrange"];
[ud setColor:[NSColor redColor] forKey:@"highlightRed"];
}
// further miscellaneous defaults
[ud setBool:YES forKey:@"NewMediaLinkIncludeIcon"];
[ud setBool:YES forKey:@"UseVisualAidWherePossibleWhenImporting"];
[ud setBool:NO forKey:@"UpdateDateModifiedOnlyAfterTextChange"];
[ud setBool:NO forKey:@"ConvertImportedURLsToWebArchives"];
[ud setObject:[NSNumber numberWithBool:YES] forKey:@"AutoEnablePrefixSearching"];
[ud setObject:[NSNumber numberWithBool:YES] forKey:@"QuickEntryCreation"];
[ud setObject:[NSNumber numberWithBool:NO] forKey:@"CalendarUseButton"];
[ud setObject:[NSNumber numberWithBool:NO] forKey:@"SearchMediaByDefault"];
[ud setObject:[NSNumber numberWithBool:NO] forKey:@"SourceListUseSmallIcons"];
[ud setObject:[NSNumber numberWithBool:NO] forKey:@"CommandWClosesWindow"];
[ud setObject:[NSNumber numberWithInteger:0] forKey:@"OpenMediaInto"];
[ud setObject:[NSNumber numberWithInteger:0] forKey:@"MediaPolicyFiles"];
[ud setObject:[NSNumber numberWithInteger:0] forKey:@"MediaPolicyDirectories"];
[ud setObject:[NSNumber numberWithInteger:0] forKey:@"DefaultVideoCodec"];
[ud setObject:[NSNumber numberWithInteger:0] forKey:@"CalendarStartDay"];
[ud setObject:[NSNumber numberWithInteger:0] forKey:@"LaunchToOption"];
[ud setObject:[NSNumber numberWithInteger:200] forKey:@"EmbeddedImageMaxWidth"];
[ud setBool:NO forKey:@"EmbeddedImageUseFullSize"];
[ud removeObjectForKey:@"BrowseSortIdentifier"];
[ud removeObjectForKey:@"NSTableView Columns QuickLinkBrowserTable"];
[ud removeObjectForKey:@"NSTableView Sort Ordering QuickLinkBrowserTable"];
[ud removeObjectForKey:@"Date Format Index"];
[ud removeObjectForKey:@"StylesBarVisible"];
[ud setObject:@"Red" forKey:@"LabelName1"];
[ud setObject:@"Orange" forKey:@"LabelName2"];
[ud setObject:@"Yellow" forKey:@"LabelName3"];
[ud setObject:@"Green" forKey:@"LabelName4"];
[ud setObject:@"Blue" forKey:@"LabelName5"];
[ud setObject:@"Purple" forKey:@"LabelName6"];
[ud setObject:@"Gray" forKey:@"LabelName7"];
[ud setInteger:0 forKey:@"AudioRecordingFormat"];
[ud setInteger:0 forKey:@"ScriptsInstallationDirectory"];
// Wrap things up
// ------------------------------------------------------------------------------------
// update the journal plist file -- WikiLinks, Blogs
[_journal performOneTwoMaintenance];
[_journal setVersion:[NSNumber numberWithInteger:250]];
// remove unneeded values from the properties dictionary
NSMutableDictionary *properties = [[[_journal properties] mutableCopyWithZone:[self zone]] autorelease];
[properties setObject:[NSNumber numberWithBool:YES] forKey:PDJournalProperShutDown];
[properties removeObjectForKey:PDJournalCollections];
[properties removeObjectForKey:PDJournalEncryptionState];
[properties removeObjectForKey:@"WikiLinks"];
[properties removeObjectForKey:@"Blogs"];
[_journal setProperties:properties];
[_journal saveProperties];
// write the index to disk
[[journal searchManager] writeIndexToDisk];
// close the search index
[[_journal searchManager] closeIndex];
// set the journal's main objects
[_journal setEntries:journalEntries];
[_journal setCollections:journalFolders];
[_journal setBlogs:journalBlogs];
//[_journal setResources:[journalEntries valueForKey:@"resources"]];
// no need to save the entries and whatnot again
//[[_journal valueForKey:@"entries"] setValue:[NSNumber numberWithBool:NO] forKey:@"dirty"];
[[_journal valueForKey:@"resources"] setValue:[NSNumber numberWithBool:YES] forKey:@"dirty"];
//[[_journal valueForKey:@"collections"] setValue:[NSNumber numberWithBool:NO] forKey:@"dirty"];
// disable searching - no need to index again
//[_journal setSaveEntryOptions:kEntrySaveDoNotIndex|kEntrySaveDoNotCollect];
// save the entire journal
[_journal save:nil];
// re-enable indexing
//[_journal setSaveEntryOptions:kEntrySaveIndexAndCollect];
// remove the old entries index
if ( [[NSFileManager defaultManager] fileExistsAtPath:[[journal journalPath] stringByAppendingPathComponent:@"Entries Index"]] )
[[NSFileManager defaultManager] removeFileAtPath:[[journal journalPath] stringByAppendingPathComponent:@"Entries Index"] handler:self];
endMessage = NSLocalizedStringFromTable(@"upgrade complete", @"UpgradeController", @"");
[progressText210 setStringValue:endMessage];
// install the lame components
// ------------------------------------------------------------------------------------
[progressText210 setStringValue:NSLocalizedStringFromTable(@"installing lame", @"UpgradeController", @"")];
[progressIndicator210 setIndeterminate:YES];
[progressIndicator210 startAnimation:self];
[self installLameComponents];
// show the relaunch button and grab the users attention
[progressIndicator210 setHidden:YES];
[NSApp endModalSession:session210];
[[self window] orderOut:self];
[NSApp requestUserAttention:NSInformationalRequest];
[NSApp runModalForWindow:licenseChanged210];
// write out the upgrade log and release it
[log117 appendString:@"Upgrade completed"];
NSError *error = nil;
if ( ![log117 writeToFile:upgradeLogPath atomically:NO encoding:NSUnicodeStringEncoding error:&error] )
NSLog(@"%s - unable to write upgrade log to %@, error %@", __PRETTY_FUNCTION__, upgradeLogPath, error);
[log117 release];
[NSApp relaunch:self];
}
- (BOOL) processResourcesLinksForEntry117To210:(JournlerEntry*)anEntry
{
//static NSString *httpScheme = @"http";
BOOL completeSuccess = YES;
NSMutableAttributedString *mutableContent = [[[anEntry valueForKey:@"attributedContent"]
mutableCopyWithZone:[self zone]] autorelease];
id attr_value;
NSRange effectiveRange;
NSRange limitRange = NSMakeRange(0, [mutableContent length]);
while (limitRange.length > 0)
{
attr_value = [mutableContent attribute:NSLinkAttributeName atIndex:limitRange.location
longestEffectiveRange:&effectiveRange inRange:limitRange];
//attr_value = [mutableContent attribute:NSLinkAttributeName atIndex:limitRange.location effectiveRange:&effectiveRange];
if ( attr_value != nil )
{
NSURL *theURL;
NSURL *replacementURL = nil;
// make sure we're dealing with a url
if ( [attr_value isKindOfClass:[NSURL class]] )
theURL = attr_value;
else if ( [attr_value isKindOfClass:[NSString class]] )
theURL = [NSURL URLWithString:attr_value];
// if the url is an entry or folder, generate a journler link for it
if ( [theURL isJournlerEntry] || [theURL isJournlerFolder] )
{
[anEntry resourceForJournlerObject:[self objectForURIRepresentation:theURL]];
}
// if the url is an address book record
else if ( [theURL isAddressBookUID] )
{
NSString *uniqueId = [[theURL absoluteString] substringFromIndex:17];
ABPerson *aPerson = (ABPerson*)[[ABAddressBook sharedAddressBook] recordForUniqueId:uniqueId];
if ( aPerson != nil )
{
// see about deriving a contact for it
JournlerResource *abResource = [anEntry resourceForABPerson:aPerson];
replacementURL = [abResource URIRepresentation];
}
else
{
// remove the attribute
[mutableContent removeAttribute:NSLinkAttributeName range:effectiveRange];
}
}
// if the url is an iPhoto ID, remove it
else if ( [theURL isPhotoID] )
{
[mutableContent removeAttribute:NSLinkAttributeName range:effectiveRange];
}
// if a replacement is available, replace the current url with it
if ( replacementURL != nil )
[mutableContent addAttribute:NSLinkAttributeName value:replacementURL range:effectiveRange];
}
limitRange = NSMakeRange(NSMaxRange(effectiveRange), NSMaxRange(limitRange) - NSMaxRange(effectiveRange));
}
[anEntry setValue:mutableContent forKey:@"attributedContent"];
return completeSuccess;
}
- (void) installLameComponents
{
/*
BOOL success = YES;
NSFileManager *fm = [NSFileManager defaultManager];
// check that the components to be installed exist
if ( ![fm fileExistsAtPath:[QTInstallController LAMEFrameworkBundlePath]] )
{
NSLog(@"JournalUpgradeController lameUpgrade - no framework at bundle path %@", [QTInstallController LAMEFrameworkBundlePath]);
success = NO; goto bail;
}
if ( ![fm fileExistsAtPath:[QTInstallController LAMEComponentBundlePath]] )
{
NSLog(@"JournalUpgradeController lameUpgrade - no component at bundle path %@", [QTInstallController LAMEComponentBundlePath]);
success = NO; goto bail;
}
// delete the components at their installed paths
if ( [fm fileExistsAtPath:[QTInstallController LAMEFrameworkInstallPath]] )
{
if ( ![fm removeFileAtPath:[QTInstallController LAMEFrameworkInstallPath] handler:self] )
{
NSLog(@"JournalUpgradeController lameUpgrade - cannot delete framework %@", [QTInstallController LAMEFrameworkInstallPath]);
success = NO; goto bail;
}
}
if ( [fm fileExistsAtPath:[QTInstallController LAMEComponentInstallPath]] )
{
if ( ![fm removeFileAtPath:[QTInstallController LAMEComponentInstallPath] handler:self] )
{
NSLog(@"JournalUpgradeController lameUpgrade - cannot delete component %@", [QTInstallController LAMEComponentInstallPath]);
success = NO; goto bail;
}
}
// actually copy the framework and component
if ( ![fm copyPath:[QTInstallController LAMEFrameworkBundlePath] toPath:[QTInstallController LAMEFrameworkInstallPath] handler:self] )
{
NSLog(@"JournalUpgradeController lameUpgrade - cannot copy framework");
success = NO; goto bail;
}
if ( ![fm copyPath:[QTInstallController LAMEComponentBundlePath] toPath:[QTInstallController LAMEComponentInstallPath] handler:self] )
{
NSLog(@"JournalUpgradeController lameUpgrade - cannot copy framework");
success = NO; goto bail;
}
bail:
if ( !success )
[[NSAlert lameInstallFailure] runModal];
*/
BOOL success = [SproutedLAMEInstaller simplyInstallLameComponents];
if ( !success ) [[NSAlert lameInstallFailure] runModal];
}
- (id) objectForURIRepresentation:(NSURL*)aURL
{
id object = nil;
NSString *abs = [aURL absoluteString];
NSString *tagID = [abs lastPathComponent];
NSString *objectType = [[abs stringByDeletingLastPathComponent] lastPathComponent];
if ( [objectType isEqualToString:@"entry"] )
object = [entriesDictionary objectForKey:[NSNumber numberWithInteger:[tagID integerValue]]];
else if ( [objectType isEqualToString:@"folder"] )
object = [foldersDictionary objectForKey:[NSNumber numberWithInteger:[tagID integerValue]]];
return object;
}
- (NSArray*) entriesForTagIDs:(NSArray*)tagIDs {
//
// utility for turning an array of entry ids into the entries themselves
NSInteger i;
NSMutableArray *entries = [[NSMutableArray alloc] initWithCapacity:[tagIDs count]];
for ( i = 0; i < [tagIDs count]; i++ ) {
id anEntry = [entriesDictionary objectForKey:[tagIDs objectAtIndex:i]];
if ( anEntry )