Force a re-serialization of Breakpoints on decode.
[macgdbp.git] / Source / AppDelegate.m
1 /*
2 * MacGDBp
3 * Copyright (c) 2007 - 2011, Blue Static <http://www.bluestatic.org>
4 *
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
10 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17 #import "AppDelegate.h"
18
19 #import <Sparkle/Sparkle.h>
20
21 #import "PreferenceNames.h"
22
23 @implementation AppDelegate
24
25 @synthesize debugger;
26 @synthesize breakpoint;
27 @synthesize loggingController = loggingController_;
28
29 /**
30 * Initialize method that is called before all other messages. This will set the default
31 * preference values.
32 */
33 + (void)load
34 {
35 @autoreleasepool {
36 NSDictionary* defaults = @{
37 kPrefPort : @9000,
38 kPrefInspectorWindowVisible : @YES,
39 kPrefPathReplacements : [NSMutableArray array],
40 kPrefFileAccessBookmarks : [NSMutableDictionary dictionary],
41 kPrefBreakOnFirstLine : @YES,
42 kPrefDebuggerAttached : @YES,
43 kPrefSelectedDebuggerSegment : @1,
44 };
45 [[NSUserDefaults standardUserDefaults] registerDefaults:defaults];
46 }
47 }
48
49 + (AppDelegate*)instance
50 {
51 return (AppDelegate*)[NSApp delegate];
52 }
53
54 - (void)applicationDidFinishLaunching:(NSNotification*)notification
55 {
56 // Record whether this user ever used the beta VersionCast feed. In the
57 // future, we will use this bit to query for unstable releases after the user
58 // has upgraded to a stable version.
59 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
60
61 BOOL usesUnstable = [defaults boolForKey:kPrefUnstableVersionCast];
62 NSURL* feedURL = [[SUUpdater sharedUpdater] feedURL];
63 usesUnstable = usesUnstable ||
64 [[feedURL absoluteString] rangeOfString:@"?unstable"].location != NSNotFound;
65 [defaults setBool:usesUnstable forKey:kPrefUnstableVersionCast];
66
67 [self _activateSecureFileAccess];
68 }
69
70 - (void)applicationWillTerminate:(NSNotification*)notification
71 {
72 [[NSUserDefaults standardUserDefaults] setBool:self.debugger.connection.autoAttach
73 forKey:kPrefDebuggerAttached];
74 }
75
76 /**
77 * Shows the debugger window
78 */
79 - (IBAction)showDebuggerWindow:(id)sender
80 {
81 [[debugger window] makeKeyAndOrderFront:self];
82 [debugger.segmentControl setSelectedSegment:1];
83 }
84
85 /**
86 * Shows the breakpoints window
87 */
88 - (IBAction)showBreakpointWindow:(id)sender
89 {
90 [[debugger window] makeKeyAndOrderFront:sender];
91 [debugger.segmentControl setSelectedSegment:2];
92 }
93
94 /**
95 * Shows the preferences window. Lazily loads the PreferencesController.
96 */
97 - (IBAction)showPreferences:(id)sender
98 {
99 if (!prefs)
100 prefs = [[PreferencesController alloc] init];
101
102 [prefs showPreferencesWindow];
103 }
104
105 /**
106 * Opens the URL to the help page
107 */
108 - (IBAction)openHelpPage:(id)sender
109 {
110 [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://www.bluestatic.org/software/macgdbp/help/"]];
111 }
112
113 /**
114 * Activates any secure file access bookmarks stored in preferences.
115 */
116 - (void)_activateSecureFileAccess
117 {
118 NSDictionary* prefs = [NSUserDefaults.standardUserDefaults objectForKey:kPrefFileAccessBookmarks];
119 NSMutableDictionary<NSString*, NSData*>* bookmarks = [NSMutableDictionary dictionaryWithDictionary:prefs];
120 for (NSString* path in bookmarks) {
121 NSURL* url = [NSURL URLWithString:path];
122
123 BOOL isStale;
124 NSError* error;
125 url = [NSURL URLByResolvingBookmarkData:bookmarks[path]
126 options:NSURLBookmarkResolutionWithSecurityScope
127 relativeToURL:nil
128 bookmarkDataIsStale:&isStale
129 error:&error];
130 if (error) {
131 NSLog(@"Failed to resolve secure bookmark for path %@: %@", path, error);
132 continue;
133 }
134 if (isStale) {
135 NSData* newBookmark = [PreferencesController secureBookmarkDataForURL:url];
136 bookmarks[url.absoluteString] = newBookmark;
137 [bookmarks removeObjectForKey:path];
138 }
139
140 if (![url startAccessingSecurityScopedResource]) {
141 NSLog(@"Failed to start accessing resource %@", path);
142 continue;
143 }
144 }
145
146 [NSUserDefaults.standardUserDefaults setObject:bookmarks forKey:kPrefFileAccessBookmarks];
147 }
148
149 @end