-
Notifications
You must be signed in to change notification settings - Fork 7
/
BSODSaverView.m
254 lines (190 loc) · 9.48 KB
/
BSODSaverView.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
//
// SCView.m
// SC
//
// Created by Simon Fransson on 2010-05-03.
// Copyright (c) 2010, Hobo Code. All rights reserved.
//
#import "BSODSaverView.h"
#define DEFAULT_CRASH_TYPE 0.5
#define DEFAULT_FATALITY 0.5
#define DEFAULT_FONT_SIZE 15.0
@interface BSODSaverView (Private)
- (void)loadFontWithName:(NSString *)fontName inBundle:(NSBundle *)bundle;
@end
@implementation BSODSaverView
NSString *const kExternalURL = @"http://www.github.com/dessibelle/Blue-Screen-Saver";
- (id)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview
{
self = [super initWithFrame:frame isPreview:isPreview];
if (self) {
// NSLog(@"initWithFrame isPreview: %d %d", isPreview, [self isPreview]);
ScreenSaverDefaults *defaults;
defaults = [ScreenSaverDefaults defaultsForModuleWithName:@"BlueScreenSaver"];
// Register our default values
[defaults registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat: DEFAULT_CRASH_TYPE], @"CrashType",
[NSNumber numberWithFloat: DEFAULT_FATALITY], @"Fatality",
[NSNumber numberWithFloat: DEFAULT_FONT_SIZE], @"FontSize",
nil]];
self.backgroundColor = [NSColor colorWithCalibratedRed:(1.0/255.0) green:(2.0/255.0) blue:(172.0/255.0) alpha:1.0];
self.captionBackgroundColor = [NSColor colorWithCalibratedRed:(169.0/255.0) green:(170.0/255.0) blue:(174.0/255.0) alpha:1.0];
self.hasUnderscoreSuffix = NO;
[self setAnimationTimeInterval:1/1.5];
/* FixedsysTTF / LucidaConsole: File names must match post script names */
NSString *bundleIdentifier = [[[NSBundle bundleForClass:[self class]] infoDictionary] objectForKey:@"CFBundleIdentifier"];
self.defaults = [ScreenSaverDefaults defaultsForModuleWithName:bundleIdentifier];
NSBundle *screenSaverBundle = [NSBundle bundleWithIdentifier:bundleIdentifier];
[self loadFontWithName:@"FixedsysTTF" inBundle:screenSaverBundle];
[self loadFontWithName:@"LucidaConsole" inBundle:screenSaverBundle];
srand48(arc4random());
double fatal_rand = drand48() -0.5 + [defaults doubleForKey:@"Fatality"];
double xp_rand = drand48() -0.5 + [defaults doubleForKey:@"CrashType"];
CGFloat fontSize = [defaults floatForKey:@"FontSize"]; // !isPreview ? [defaults floatForKey:@"FontSize"] : 6.0;
self.fatal = fatal_rand >= 0.5;
self.xp = xp_rand >= 0.5;
if (self.xp) {
self.font = [NSFont fontWithName:@"LucidaConsole" size:fontSize];
} else {
self.font = [NSFont fontWithName:@"FixedsysTTF" size:fontSize];
}
/* 9.X : VMM / DiskTSD / voltrack */
if (self.xp) {
NSInteger addr1 = rand(),
addr2 = rand(),
addr3 = rand(),
addr4 = rand(),
addr5 = rand(),
addr6 = rand(),
addr7 = rand(),
addr8 = rand();
self.contentString = [NSString stringWithFormat:@"A problem has been detected and Windows has been shut down to prevent damage\nto your computer.\n\nThe problem seems to be caused by the following file: SPCMDCON.SYS\n\nPAGE_FAULT_IN_NONPAGED_AREA\n\nIf this is the first time you've seen this stop error screen,\nrestart your computer. If this screen appears again, follow\nthese steps:\n\nCheck to make sure any new hardware or software is properly installed.\nIf this is a new installation, ask your hardware or software manufacturer\nfor any Windows updates you might need.\n\nIf problems continue, disable or remove any newly installed hardware\nor software. Disable BIOS memory options such as caching or shadowing.\nIf you need to use Safe Mode to remove or disable components, restart\nyour computer, press F8 to select Advanced Startup Options, and then\nselect Safe Mode.\n\nTechnical information:\n\n*** STOP: 0x%08lX (0x%08lX, 0x%08lX, 0x%08lX, 0x%08lX)\n\n\n*** SPCMDCON.SES - Address %08lX base at %08lX, DateStamp %08lx ", addr1, addr2, addr3, addr4, addr5, addr6, addr7, addr8];
} else if (self.fatal) {
NSInteger addr1 = rand() % (0xFFFF - 0x1000) + 0x1000,
addr2 = rand(),
addr3 = rand(),
exception = rand() % (0x0F - 0x01) + 0x01;
self.contentString = [NSString stringWithFormat:@"A fatal exception %02lX has occured at %04lX:%08lX in VxD VMM(01) + \n%08lX. The current application will be terminated.\n\n* Press any key to terminate the current application.\n* Press CTRL+ALT+RESET to restart your computer. You will\n lose any unsaved information in all applications.\n\n\n Press any key to continue ", exception, addr1, addr2, addr3];
} else {
NSInteger addr1 = rand() % (0xFFFF - 0x1000) + 0x1000,
addr2 = rand(),
addr3 = rand(),
addr4 = rand() % (0xFFFF - 0x1000) + 0x1000,
addr5 = rand(),
addr6 = rand(),
exception = rand() % (0x0F - 0x01) + 0x01;
self.contentString = [NSString stringWithFormat:@"An exception %02lX has occured at %04lX:%08lX in VxD VMM(01) + \n%08lX. This was called from %04lX:%08lX in VxD VMM(01) + \n%08lX. It may be possible to continue normally.\n\n* Press any key to terminate the current application.\n* Press CTRL+ALT+RESET to restart your computer. You will\n lose any unsaved information in all applications.\n\n\n Press any key to continue ", exception, addr1, addr2, addr3, addr4, addr5, addr6];
}
self.captionString = @" Windows ";
self.drawingAttributes = [NSDictionary dictionaryWithObjectsAndKeys:self.font, NSFontAttributeName,
[NSColor whiteColor], NSForegroundColorAttributeName,
nil];
self.captionDrawingAttributes = [NSDictionary dictionaryWithObjectsAndKeys:self.font, NSFontAttributeName,
self.backgroundColor, NSForegroundColorAttributeName,
self.captionBackgroundColor, NSBackgroundColorAttributeName,
nil];
}
return self;
}
- (void)animateOneFrame
{
self.hasUnderscoreSuffix = !self.hasUnderscoreSuffix;
[self setNeedsDisplay:YES];
}
- (void)drawRect:(NSRect)rect
{
/*
if (![self isPreview])
[[NSGraphicsContext currentContext] setShouldAntialias:NO];
*/
[[NSGraphicsContext currentContext] setShouldAntialias:NO];
[self.backgroundColor set];
[self.font set];
/*
* ▋ █ ▊
*/
NSString *message = [self.contentString stringByAppendingString:(self.hasUnderscoreSuffix ? @"_" : @"▋")];
NSRectFill(rect);
NSSize captionSize = [self.captionString sizeWithAttributes:self.captionDrawingAttributes];
NSSize contentSize = [message sizeWithAttributes:self.drawingAttributes];
NSRect captionRect = NSMakeRect((rect.size.width - captionSize.width) / 2.0,
((rect.size.height + contentSize.height) / 2.0) + (self.xp ? 0 : captionSize.height),
captionSize.width,
captionSize.height);
NSRect contentRect = NSMakeRect((rect.size.width - contentSize.width) / 2.0,
((rect.size.height - contentSize.height) / 2.0) - (self.xp ? 0 : captionSize.height),
contentSize.width,
contentSize.height);
if (!self.xp)
[self.captionString drawInRect:captionRect withAttributes:self.captionDrawingAttributes];
[message drawInRect:contentRect withAttributes:self.drawingAttributes];
}
+ (BOOL)performGammaFade
{
return NO;
}
- (BOOL)hasConfigureSheet
{
return YES;
}
- (NSWindow *)configureSheet
{
ScreenSaverDefaults *defaults = [ScreenSaverDefaults defaultsForModuleWithName:@"BlueScreenSaver"];
if (!self.configSheet)
{
NSArray *topLevelObjects;
if (![[NSBundle bundleForClass:[self class]] loadNibNamed:@"ConfigureSheet" owner:self topLevelObjects:&topLevelObjects])
{
NSLog( @"Failed to load configure sheet." );
NSBeep();
}
}
[self.fatalitySlider setFloatValue:[defaults floatForKey:@"Fatality"]];
[self.typeSlider setFloatValue:[defaults floatForKey:@"CrashType"]];
[self.fontSizeSlider setFloatValue:[defaults floatForKey:@"FontSize"]];
return self.configSheet;
}
# pragma mark Private
- (void)loadFontWithName:(NSString *)fontName inBundle:(NSBundle *)bundle {
NSArray *availableFonts = [[NSFontManager sharedFontManager] availableFonts];
if (![availableFonts containsObject:fontName]) {
NSURL *fontURL = [bundle URLForResource:fontName withExtension:@"ttf" subdirectory:@"Fonts"];
assert(fontURL);
CFErrorRef error = NULL;
if (!CTFontManagerRegisterFontsForURL((__bridge CFURLRef)fontURL, kCTFontManagerScopeProcess, &error))
{
CFShow(error);
}
}
}
#pragma mark IBACtions
- (IBAction)configSheetCancelAction:(id)sender
{
if ([NSWindow respondsToSelector:@selector(endSheet:)])
{
[[self.configSheet sheetParent] endSheet:self.configSheet returnCode:NSModalResponseCancel];
} else {
[[NSApplication sharedApplication] endSheet:self.configSheet];
}
}
- (IBAction)configSheetOKAction:(id)sender
{
ScreenSaverDefaults *defaults;
defaults = [ScreenSaverDefaults defaultsForModuleWithName:@"BlueScreenSaver"];
[defaults setFloat:self.fatalitySlider.floatValue forKey:@"Fatality"];
[defaults setFloat:self.typeSlider.floatValue forKey:@"CrashType"];
[defaults setFloat:self.fontSizeSlider.floatValue forKey:@"FontSize"];
[defaults synchronize];
[self configSheetCancelAction:sender];
}
- (IBAction)URLTextFieldClicked:(id)sender
{
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:kExternalURL]];
}
- (IBAction)resetDefaultSettingsClicked:(id)sender;
{
self.fatalitySlider.floatValue = DEFAULT_CRASH_TYPE;
self.typeSlider.floatValue = DEFAULT_CRASH_TYPE;
self.fontSizeSlider.floatValue = DEFAULT_FONT_SIZE;
}
@end