Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

352 lines
8.8 KiB

  1. package Win32::Shortcut;
  2. #######################################################################
  3. #
  4. # Win32::Shortcut - Perl Module for Shell Link Interface
  5. # ^^^^^^^^^^^^^^^
  6. # This module creates an object oriented interface to the Win32
  7. # Shell Links (IShellLink interface).
  8. #
  9. # Version: 0.03 (07 Apr 1997)
  10. #
  11. #######################################################################
  12. require Exporter; # to export the constants to the main:: space
  13. require DynaLoader; # to dynuhlode the module.
  14. @ISA= qw( Exporter DynaLoader );
  15. @EXPORT = qw(
  16. SW_SHOWMAXIMIZED
  17. SW_SHOWMINNOACTIVE
  18. SW_SHOWNORMAL
  19. );
  20. #######################################################################
  21. # This AUTOLOAD is used to 'autoload' constants from the constant()
  22. # XS function. If a constant is not found then control is passed
  23. # to the AUTOLOAD in AutoLoader.
  24. #
  25. sub AUTOLOAD {
  26. my($constname);
  27. ($constname = $AUTOLOAD) =~ s/.*:://;
  28. #reset $! to zero to reset any current errors.
  29. $!=0;
  30. my $val = constant($constname, @_ ? $_[0] : 0);
  31. if ($! != 0) {
  32. # [dada] This results in an ugly Autoloader error
  33. #if ($! =~ /Invalid/) {
  34. # $AutoLoader::AUTOLOAD = $AUTOLOAD;
  35. # goto &AutoLoader::AUTOLOAD;
  36. #} else {
  37. # [dada] ... I prefer this one :)
  38. ($pack, $file, $line) = caller;
  39. undef $pack; # [dada] and get rid of "used only once" warning...
  40. die "Win32::Shortcut::$constname is not defined, used at $file line $line.";
  41. #}
  42. }
  43. eval "sub $AUTOLOAD { $val }";
  44. goto &$AUTOLOAD;
  45. }
  46. #######################################################################
  47. # STATIC OBJECT PROPERTIES
  48. #
  49. $VERSION = "0.03";
  50. #######################################################################
  51. # PUBLIC METHODS
  52. #
  53. #======== ### CLASS CONSTRUCTOR
  54. sub new {
  55. #========
  56. my($class, $file) = @_;
  57. my $self = {};
  58. my $ilink = 0;
  59. my $ifile = 0;
  60. ($ilink, $ifile) = _Instance();
  61. if($ilink and $ifile) {
  62. $self->{'ilink'} = $ilink;
  63. $self->{'ifile'} = $ifile;
  64. bless $self;
  65. # Initialize properties
  66. $self->{'File'} = "";
  67. $self->{'Path'} = "";
  68. $self->{'Arguments'} = "";
  69. $self->{'WorkingDirectory'} = "";
  70. $self->{'Description'} = "";
  71. $self->{'ShowCmd'} = 0;
  72. $self->{'Hotkey'} = 0;
  73. $self->{'IconLocation'} = "";
  74. $self->{'IconNumber'} = 0;
  75. $self->Load($file) if $file;
  76. } else {
  77. return undef;
  78. }
  79. $self;
  80. }
  81. #=========
  82. sub Load {
  83. #=========
  84. my($self, $file) = @_;
  85. return undef unless ref($self);
  86. my $result = _Load($self->{'ilink'}, $self->{'ifile'}, $file);
  87. if(defined($result)) {
  88. # fill the properties of $self
  89. $self->{'File'} = $file;
  90. $self->{'Path'} = _GetPath($self->{'ilink'}, $self->{'ifile'},0);
  91. $self->{'ShortPath'} = _GetPath($self->{'ilink'}, $self->{'ifile'},1);
  92. $self->{'Arguments'} = _GetArguments($self->{'ilink'}, $self->{'ifile'});
  93. $self->{'WorkingDirectory'} = _GetWorkingDirectory($self->{'ilink'}, $self->{'ifile'});
  94. $self->{'Description'} = _GetDescription($self->{'ilink'}, $self->{'ifile'});
  95. $self->{'ShowCmd'} = _GetShowCmd($self->{'ilink'}, $self->{'ifile'});
  96. $self->{'Hotkey'} = _GetHotkey($self->{'ilink'}, $self->{'ifile'});
  97. ($self->{'IconLocation'},
  98. $self->{'IconNumber'}) = _GetIconLocation($self->{'ilink'}, $self->{'ifile'});
  99. }
  100. return $result;
  101. }
  102. #========
  103. sub Set {
  104. #========
  105. my($self, $path, $arguments, $dir, $description, $show, $hotkey,
  106. $iconlocation, $iconnumber) = @_;
  107. return undef unless ref($self);
  108. $self->{'Path'} = $path;
  109. $self->{'Arguments'} = $arguments;
  110. $self->{'WorkingDirectory'} = $dir;
  111. $self->{'Description'} = $description;
  112. $self->{'ShowCmd'} = $show;
  113. $self->{'Hotkey'} = $hotkey;
  114. $self->{'IconLocation'} = $iconlocation;
  115. $self->{'IconNumber'} = $iconnumber;
  116. return 1;
  117. }
  118. #=========
  119. sub Save {
  120. #=========
  121. my($self, $file) = @_;
  122. return undef unless ref($self);
  123. return undef if not $file and not $self->{'File'};
  124. $file = $self->{'File'} if not $file;
  125. _SetPath($self->{'ilink'}, $self->{'ifile'}, $self->{'Path'});
  126. _SetArguments($self->{'ilink'}, $self->{'ifile'}, $self->{'Arguments'});
  127. _SetWorkingDirectory($self->{'ilink'}, $self->{'ifile'}, $self->{'WorkingDirectory'});
  128. _SetDescription($self->{'ilink'}, $self->{'ifile'}, $self->{'Description'});
  129. _SetShowCmd($self->{'ilink'}, $self->{'ifile'}, $self->{'ShowCmd'});
  130. _SetHotkey($self->{'ilink'}, $self->{'ifile'}, $self->{'Hotkey'});
  131. _SetIconLocation($self->{'ilink'}, $self->{'ifile'},
  132. $self->{'IconLocation'}, $self->{'IconNumber'});
  133. my $result = _Save($self->{'ilink'}, $self->{'ifile'}, $file);
  134. return $result;
  135. }
  136. #============
  137. sub Resolve {
  138. #============
  139. my($self, $flags) = @_;
  140. return undef unless ref($self);
  141. $flags = 1 unless defined($flags);
  142. my $result = _Resolve($self->{'ilink'}, $self->{'ifile'}, $flags);
  143. return $result;
  144. }
  145. #==========
  146. sub Close {
  147. #==========
  148. my($self) = @_;
  149. return undef unless ref($self);
  150. my $result = _Release($self->{'ilink'}, $self->{'ifile'});
  151. $self->{'released'} = 1;
  152. return $result;
  153. }
  154. #=========
  155. sub Path {
  156. #=========
  157. my($self, $value) = @_;
  158. return undef unless ref($self);
  159. if(not defined($value)) {
  160. return $self->{'Path'};
  161. } else {
  162. $self->{'Path'} = $value;
  163. }
  164. return $self->{'Path'};
  165. }
  166. #==============
  167. sub ShortPath {
  168. #==============
  169. my($self) = @_;
  170. return undef unless ref($self);
  171. return $self->{'ShortPath'};
  172. }
  173. #==============
  174. sub Arguments {
  175. #==============
  176. my($self, $value) = @_;
  177. return undef unless ref($self);
  178. if(not defined($value)) {
  179. return $self->{'Arguments'};
  180. } else {
  181. $self->{'Arguments'} = $value;
  182. }
  183. return $self->{'Arguments'};
  184. }
  185. #=====================
  186. sub WorkingDirectory {
  187. #=====================
  188. my($self, $value) = @_;
  189. return undef unless ref($self);
  190. if(not defined($value)) {
  191. return $self->{'WorkingDirectory'};
  192. } else {
  193. $self->{'WorkingDirectory'} = $value;
  194. }
  195. return $self->{'WorkingDirectory'};
  196. }
  197. #================
  198. sub Description {
  199. #================
  200. my($self, $value) = @_;
  201. return undef unless ref($self);
  202. if(not defined($value)) {
  203. return $self->{'Description'};
  204. } else {
  205. $self->{'Description'} = $value;
  206. }
  207. return $self->{'Description'};
  208. }
  209. #============
  210. sub ShowCmd {
  211. #============
  212. my($self, $value) = @_;
  213. return undef unless ref($self);
  214. if(not defined($value)) {
  215. return $self->{'ShowCmd'};
  216. } else {
  217. $self->{'ShowCmd'} = $value;
  218. }
  219. return $self->{'ShowCmd'};
  220. }
  221. #===========
  222. sub Hotkey {
  223. #===========
  224. my($self, $value) = @_;
  225. return undef unless ref($self);
  226. if(not defined($value)) {
  227. return $self->{'Hotkey'};
  228. } else {
  229. $self->{'Hotkey'} = $value;
  230. }
  231. return $self->{'Hotkey'};
  232. }
  233. #=================
  234. sub IconLocation {
  235. #=================
  236. my($self, $value) = @_;
  237. return undef unless ref($self);
  238. if(not defined($value)) {
  239. return $self->{'IconLocation'};
  240. } else {
  241. $self->{'IconLocation'} = $value;
  242. }
  243. return $self->{'IconLocation'};
  244. }
  245. #===============
  246. sub IconNumber {
  247. #===============
  248. my($self, $value) = @_;
  249. return undef unless ref($self);
  250. if(not defined($value)) {
  251. return $self->{'IconNumber'};
  252. } else {
  253. $self->{'IconNumber'} = $value;
  254. }
  255. return $self->{'IconNumber'};
  256. }
  257. #============
  258. sub Version {
  259. #============
  260. # [dada] to get rid of the "used only once" warning...
  261. return $VERSION;
  262. }
  263. #######################################################################
  264. # PRIVATE METHODS
  265. #
  266. #============ ### CLASS DESTRUCTOR
  267. sub DESTROY {
  268. #============
  269. my($self) = @_;
  270. if(not $self->{'released'}) {
  271. _Release($self->{'ilink'}, $self->{'ifile'});
  272. }
  273. }
  274. #======== ### PACKAGE DESTRUCTOR
  275. sub END {
  276. #========
  277. # print "Exiting...\n";
  278. _Exit();
  279. }
  280. #######################################################################
  281. # dynamically load in the Shortcut.pll module.
  282. #
  283. bootstrap Win32::Shortcut;
  284. # Preloaded methods go here.
  285. #Currently Autoloading is not implemented in Perl for win32
  286. # Autoload methods go after __END__, and are processed by the autosplit program.
  287. 1;
  288. __END__