This repository has been archived by the owner on Oct 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
EFIDropKextsView.m
182 lines (157 loc) · 5.21 KB
/
EFIDropKextsView.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
//
// EFIDSDTView.m
//
// Created by Eduard Sionov on 1/18/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "EFIDropKextsView.h"
@implementation EFIDropKextsView
- (void)awakeFromNib {
NSString *appPath = [[NSBundle mainBundle] bundlePath];
NSString *dropHereImagePath = [[NSString alloc] initWithString:[appPath stringByAppendingString:@"/Contents/Resources/images/dropHere.png"]];
NSImage *dropHereImage = [[NSImage alloc] initWithContentsOfFile:dropHereImagePath];
[self setImage:dropHereImage];
kexts = [NSMutableArray array];
[kexts retain];
}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
if ((NSDragOperationGeneric & [sender draggingSourceOperationMask])
== NSDragOperationGeneric)
{
//this means that the sender is offering the type of operation we want
//return that we want the NSDragOperationGeneric operation that they
//are offering
highlight=YES;
[self setNeedsDisplay: YES];
return NSDragOperationGeneric;
}
else
{
//since they aren't offering the type of operation we want, we have
//to tell them we aren't interested
highlight=YES;
[self setNeedsDisplay: YES];
return NSDragOperationNone;
}
}
- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender
{
if ((NSDragOperationGeneric & [sender draggingSourceOperationMask])
== NSDragOperationGeneric)
{
//this means that the sender is offering the type of operation we want
//return that we want the NSDragOperationGeneric operation that they
//are offering
highlight=YES;
[self setNeedsDisplay: YES];
return NSDragOperationGeneric;
}
else
{
//since they aren't offering the type of operation we want, we have
//to tell them we aren't interested
highlight=YES;
[self setNeedsDisplay: YES];
return NSDragOperationNone;
}
}
- (void)draggingExited:(id <NSDraggingInfo>)sender
{
//we aren't particularily interested in this so we will do nothing
//this is one of the methods that we do not have to implement
highlight=NO;//remove highlight of the drop zone
[self setNeedsDisplay: NO];
}
- (void)draggingEnded:(id <NSDraggingInfo>)sender
{
//we don't do anything in our implementation
//this could be ommitted since NSDraggingDestination is an infomal
//protocol and returns nothing
highlight=NO;//remove highlight of the drop zone
[self setNeedsDisplay: NO];
}
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
{
return YES;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
NSPasteboard *paste = [sender draggingPasteboard];
//gets the dragging-specific pasteboard from the sender
//need to know is this file dsdt.aml
//we have a list of file names in an NSData object
NSArray *fileArray =
[paste propertyListForType:@"NSFilenamesPboardType"];
//be caseful since this method returns id.
//We just happen to know that it will be an array.
for (int i=0;i < [fileArray count]; i++) {
NSString *path = [fileArray objectAtIndex:i];
NSString *fileName = [[NSString alloc] initWithString:[path substringWithRange:NSMakeRange([path length] - 5, 5)]];
//application path
NSString *appPath = [[NSBundle mainBundle] bundlePath];
if ([fileName isEqualToString:@".kext"]) {
NSString *goodImagePath = [[NSString alloc] initWithString:[appPath stringByAppendingString:@"/Contents/Resources/images/good.png"]];
NSImage *goodImage = [[NSImage alloc] initWithContentsOfFile:goodImagePath];
[kexts addObject:[[NSString alloc]initWithString:path]];
[kexts retain];
[self setImage:goodImage];
} else {
NSString *badImagePath = [[NSString alloc] initWithString:[appPath stringByAppendingString:@"/Contents/Resources/images/bad.png"]];
NSImage *badImage = [[NSImage alloc] initWithContentsOfFile:badImagePath];
[self setImage:badImage];
NSRunAlertPanel(@"Paste Error",
[NSString stringWithFormat:
@"Drag and drop \".kext\" files",
path], nil, nil, nil);
return NO;
}
}
[self setNeedsDisplay:NO]; //redraw us with the new image
return YES;
}
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender
{
//re-draw the view with our new data
[self setNeedsDisplay:YES];
}
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
[self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType,
NSFilenamesPboardType, nil]];
return self;
}
- (void)dealloc
{
[self unregisterDraggedTypes];
[super dealloc];
}
- (void)drawRect:(NSRect)rect
{
NSRect ourBounds = [self bounds];
NSImage *image = [self image];
[super drawRect:rect];
[image compositeToPoint:(ourBounds.origin) operation:NSCompositeSourceOver];
[super drawRect:rect];//do the usual draw operation to display the image
if(highlight){
//highlight by overlaying a gray border
[[NSColor grayColor] set];
[NSBezierPath setDefaultLineWidth: 5];
[NSBezierPath strokeRect: rect];
}
}
- (void)setImage:(NSImage *)newImage
{
NSImage *temp = [newImage retain];
[_ourImage release];
_ourImage = temp;
}
- (NSImage *)image
{
return _ourImage;
}
- (NSMutableArray*)getKexts {
return kexts;
}
@end