]> Dogcows Code - chaz/thecheat/blob - Process.m
The Cheat 1.2.3
[chaz/thecheat] / Process.m
1
2 // **********************************************************************
3 // The Cheat - A universal game cheater for Mac OS X
4 // (C) 2003-2005 Chaz McGarvey (BrokenZipper)
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 1, or (at your option)
9 // any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 //
20
21 #import "Process.h"
22
23
24 @interface Process ( PrivateAPI )
25
26 - (void)_setName:(NSString *)name;
27 - (void)_setVersion:(NSString *)version;
28 - (void)_setIcon:(NSImage *)icon;
29 - (void)_setPID:(pid_t)pid;
30
31 @end
32
33
34 @implementation Process
35
36
37 - (id)initWithName:(NSString *)name version:(NSString *)version icon:(NSImage *)icon pid:(pid_t)pid
38 {
39 if ( self = [super init] ) {
40 [self _setName:name];
41 [self _setVersion:version];
42 [self _setIcon:icon];
43 [self _setPID:pid];
44 }
45 return self;
46 }
47
48 - (id)initWithName:(NSString *)name version:(NSString *)version icon:(NSImage *)icon
49 {
50 return [self initWithName:name version:version icon:icon pid:0];
51 }
52
53 - (id)initWithName:(NSString *)name version:(NSString *)version
54 {
55 return [self initWithName:name version:version icon:nil pid:0];
56 }
57
58 - (void)dealloc
59 {
60 // release local objects
61 [_name release];
62 [_version release];
63 [_icon release];
64
65 [super dealloc];
66 }
67
68
69 // #############################################################################
70 #pragma mark NSCoding
71 // #############################################################################
72
73 - (id)copyWithZone:(NSZone *)zone
74 {
75 return [[Process allocWithZone:zone] initWithName:_name version:_version icon:_icon pid:_pid];
76 }
77
78
79 // #############################################################################
80 #pragma mark NSCoding
81 // #############################################################################
82
83 - (id)initWithCoder:(NSCoder *)coder
84 {
85 if ( self = [super init] )
86 {
87 [self _setName:[coder decodeObject]];
88 [self _setVersion:[coder decodeObject]];
89 //[self setIcon:[coder decodeObject]];
90 [coder decodeValueOfObjCType:@encode(pid_t) at:&_pid];
91 }
92 return self;
93 }
94
95 - (void)encodeWithCoder:(NSCoder *)coder
96 {
97 [coder encodeObject:_name];
98 [coder encodeObject:_version];
99 //[coder encodeObject:_icon];
100 [coder encodeValueOfObjCType:@encode(pid_t) at:&_pid];
101 }
102
103
104 #pragma mark NSObject Override
105
106 - (BOOL)isEqual:(id)anObject
107 {
108 if ( [_name isEqualToString:[(Process *)anObject name]] &&
109 [_version isEqualToString:[(Process *)anObject version]] &&
110 _pid == [(Process *)anObject pid] ) {
111 // they are the same process
112 return YES;
113 }
114 return NO;
115 }
116
117 - (unsigned)hash
118 {
119 return [[NSString stringWithFormat:@"%@%@%u", _name, _version, _pid] hash];
120 }
121
122
123 - (BOOL)sameApplicationAs:(id)anObject
124 {
125 if ( [_name isEqualToString:[(Process *)anObject name]] &&
126 [_version isEqualToString:[(Process *)anObject version]] ) {
127 // they are the same application
128 return YES;
129 }
130 return NO;
131 }
132
133
134 #pragma mark Accessors
135
136 - (NSString *)name
137 {
138 return _name;
139 }
140
141 - (NSString *)version
142 {
143 return _version;
144 }
145
146 - (NSImage *)icon
147 {
148 return _icon;
149 }
150
151 - (pid_t)pid
152 {
153 return _pid;
154 }
155
156
157 - (void)_setName:(NSString *)name
158 {
159 if ( !name ) {
160 name = [NSString stringWithString:@"Unknown Process"];
161 }
162 [name retain];
163 [_name release];
164 _name = name;
165 }
166
167 - (void)_setVersion:(NSString *)version
168 {
169 if ( !version ) {
170 version = [NSString stringWithString:@"Unknown Version"];
171 }
172 [version retain];
173 [_version release];
174 _version = version;
175 }
176
177 - (void)_setIcon:(NSImage *)icon
178 {
179 [icon retain];
180 [_icon release];
181 _icon = icon;
182
183 // resize new image
184 [_icon setScalesWhenResized:YES];
185 [_icon setSize:NSMakeSize(16,16)];
186 }
187
188 - (void)_setPID:(pid_t)pid
189 {
190 _pid = pid;
191 }
192
193
194 @end
This page took 0.0405 seconds and 4 git commands to generate.