1 21 22 package com.izforge.izpack.util.os; 23 24 import java.io.File ; 25 import java.io.UnsupportedEncodingException ; 26 import java.util.Vector ; 27 28 import com.izforge.izpack.util.Debug; 29 import com.izforge.izpack.util.StringTool; 30 31 32 38 39 public class Win_Shortcut extends Shortcut 40 { 41 42 46 private ShellLink shortcut; 50 51 private static String myClass = Win_Shortcut.class.getName() + ": "; 52 53 private static final String CLASS = "Class: "; 54 55 56 private static final boolean SUPPORTED = true; 57 58 59 73 public void initialize(int type, String name) throws Exception 74 { 75 Debug.log( CLASS + myClass + ".initialize() '" + Integer.toString(type)+ "', '" + name + "'" ); 76 switch (type) 77 { 78 case APPLICATIONS: { 79 shortcut = new ShellLink(ShellLink.PROGRAM_MENU, name); 80 break; 81 } 82 case START_MENU: { 83 shortcut = new ShellLink(ShellLink.START_MENU, name); 84 break; 85 } 86 case DESKTOP: { 87 shortcut = new ShellLink(ShellLink.DESKTOP, name); 88 break; 89 } 90 case START_UP: { 91 shortcut = new ShellLink(ShellLink.STARTUP, name); 92 break; 93 } 94 default: { 95 shortcut = new ShellLink(ShellLink.PROGRAM_MENU, name); 96 break; 97 } 98 } 99 } 100 101 102 113 public String getBasePath() throws Exception 114 { 115 String result = shortcut.getLinkPath(shortcut.getUserType()); 116 Debug.log( CLASS + myClass + ".getBasePath() '" + result + "'" ); 117 return result; 118 } 119 120 133 public Vector getProgramGroups(int userType) 134 { 135 int logentry = 0; 136 Debug.log( CLASS + myClass + ".getProgramGroups()-" + logentry++ + " '" + Integer.toString(userType) + "'" ); 137 int type = ShellLink.CURRENT_USER; 141 142 if (userType == ALL_USERS) 143 { 144 type = ShellLink.ALL_USERS; 145 } 146 else 147 { 148 type = ShellLink.CURRENT_USER; 149 } 150 151 String linkPath = shortcut.getLinkPath(type); 156 157 Debug.log( CLASS + myClass + ".getProgramGroups()-" + logentry++ + " '" + linkPath + "'" ); 158 159 if (linkPath == null) { return (new Vector ()); } 163 164 File path = new File (linkPath); 165 File [] file = path.listFiles(); 166 167 Vector groups = new Vector (); 172 173 if (file != null) 174 { 175 for (int i = 0; i < file.length; i++) 176 { 177 File aFile = file[i]; 178 String aFilename = aFile.getName(); 179 if (aFile.isDirectory()) 180 { 181 182 Debug.log( CLASS + myClass + ".getProgramGroups()-" + logentry++ + " '" + aFilename + "'" ); 183 groups.add( aFilename ); 184 } 185 else 186 Debug.log( CLASS + myClass + ".getProgramGroups()-" + logentry++ + " Skip (NoDirectory): '" + aFilename + "'" ); 187 } 188 } 189 190 return (groups); 191 } 192 193 194 201 public String getFileName() 202 { 203 String aFilename = shortcut.getFileName(); 204 Debug.log( CLASS + myClass + ".getFileName() '" + aFilename + "'" ); 205 return( aFilename ); 206 } 207 208 209 219 public String getDirectoryCreated() 220 { 221 String directoryCreated = shortcut.getDirectoryCreated(); 222 Debug.log( CLASS + myClass + ".getDirectoryCreated() '" + directoryCreated + "'" ); 223 return( directoryCreated ); 224 } 225 226 227 232 public boolean multipleUsers() 233 { 234 boolean result = false; 235 String allUsers = shortcut.getallUsersLinkPath(); 238 239 Debug.log( CLASS + myClass + ".multipleUsers()-1 '" + allUsers + "'" ); 240 241 String currentUsers = shortcut.getcurrentUserLinkPath(); 242 Debug.log( CLASS + myClass + ".multipleUsers()-2 '" + currentUsers + "'" ); 243 244 if( allUsers == null || currentUsers == null ) 245 result = false; 246 else 247 result = allUsers.length() > 0 && currentUsers.length() > 0; 248 249 Debug.log( CLASS + myClass + ".multipleUsers()-3 '" + result + "'" ); 250 return (result); 251 } 252 253 254 260 public boolean supported() 261 { 262 Debug.log( CLASS + myClass + ".supported() '" + SUPPORTED + "'" ); 263 return( SUPPORTED ); 264 } 265 266 267 272 public void setArguments(String arguments) 273 { 274 Debug.log( CLASS + myClass + ".setArguments() '" + arguments + "'" ); 275 shortcut.setArguments(arguments); 276 } 277 278 279 284 public void setDescription(String description) 285 { 286 Debug.log( CLASS + myClass + ".setDescription() '" + description + "'" ); 287 shortcut.setDescription( description ); 288 } 289 290 291 298 public void setIconLocation(String path, int index) 299 { 300 Debug.log( CLASS + myClass + ".setIconLocation() '" + path + "', '" + Integer.toString(index) + "'" ); 301 shortcut.setIconLocation(path, index); 302 } 303 304 305 310 public String getIconLocation() 311 { 312 String result = shortcut.getIconLocation(); 313 Debug.log( CLASS + myClass + ".getIconLocation() '" + result + "'" ); 314 return result; 315 } 316 317 318 323 public void setProgramGroup(String groupName) 324 { 325 Debug.log( CLASS + myClass + ".setProgramGroup() '" + groupName + "'" ); 326 shortcut.setProgramGroup(groupName); 327 } 328 329 330 351 public void setShowCommand(int show) throws IllegalArgumentException 352 { 353 Debug.log( CLASS + myClass + ".setShowCommand() '" + Integer.toString(show) + "'" ); 354 switch (show) 355 { 356 case HIDE: { 357 shortcut.setShowCommand(ShellLink.MINNOACTIVE); 358 break; 359 } 360 case NORMAL: { 361 shortcut.setShowCommand(ShellLink.NORMAL); 362 break; 363 } 364 case MINIMIZED: { 365 shortcut.setShowCommand(ShellLink.MINNOACTIVE); 366 break; 367 } 368 case MAXIMIZED: { 369 shortcut.setShowCommand(ShellLink.MAXIMIZED); 370 break; 371 } 372 default: { 373 throw (new IllegalArgumentException (show + "is not recognized as a show command")); 374 } 375 } 376 } 377 378 382 public int getShowCommand() 383 { 384 int showCommand = shortcut.getShowCommand(); 385 386 Debug.log( CLASS + myClass + ".getShowCommand() '" + Integer.toString(showCommand) + "'" ); 387 388 switch (showCommand) 389 { 390 case ShellLink.NORMAL: 391 showCommand = NORMAL; 392 break; 393 case ShellLink.MINNOACTIVE: 395 case ShellLink.MINIMIZED: 396 showCommand = MINIMIZED; 397 break; 398 case ShellLink.MAXIMIZED: 399 showCommand = MAXIMIZED; 400 break; 401 default: 402 break; 403 } 404 405 return showCommand; 406 } 407 408 409 414 public void setTargetPath(String path) 415 { 416 Debug.log( CLASS + myClass + ".setTargetPath() '" + path + "'" ); 417 shortcut.setTargetPath(path); 418 } 419 420 421 426 public void setWorkingDirectory(String dir) 427 { 428 Debug.log( CLASS + myClass + ".setWorkingDirectory() '" + dir + "'" ); 429 shortcut.setWorkingDirectory(dir); 430 } 431 432 433 438 public String getWorkingDirectory() 439 { 440 String result = shortcut.getWorkingDirectory(); 441 Debug.log( CLASS + myClass + ".getWorkingDirectory() '" + result + "'" ); 442 return result; 443 } 444 445 446 452 public void setLinkName(String name) 453 { 454 Debug.log( CLASS + myClass + ".setLinkName() '" + name + "'" ); 455 shortcut.setLinkName(name); 456 } 457 458 459 469 public int getLinkType() 470 { 471 int typ = shortcut.getLinkType(); 472 Debug.log( CLASS + myClass + ".getLinkType() '" + typ + "'" ); 473 switch (typ) 474 { 475 case ShellLink.DESKTOP: 476 typ = DESKTOP; 477 break; 478 case ShellLink.PROGRAM_MENU: 479 typ = APPLICATIONS; 480 break; 481 case ShellLink.START_MENU: 482 typ = START_MENU; 483 break; 484 case ShellLink.STARTUP: 485 typ = START_UP; 486 break; 487 default: 488 break; 489 } 490 491 return typ; 492 } 493 494 495 510 public void setLinkType(int type) throws IllegalArgumentException , UnsupportedEncodingException 511 { 512 Debug.log( CLASS + myClass + ".setLinkType() '" + type + "'" ); 513 switch (type) 514 { 515 case DESKTOP: { 516 shortcut.setLinkType(ShellLink.DESKTOP); 517 break; 518 } 519 case APPLICATIONS: { 520 shortcut.setLinkType(ShellLink.PROGRAM_MENU); 521 break; 522 } 523 case START_MENU: { 524 shortcut.setLinkType(ShellLink.START_MENU); 525 break; 526 } 527 case START_UP: { 528 shortcut.setLinkType(ShellLink.STARTUP); 529 break; 530 } 531 default: { 532 throw (new IllegalArgumentException (type + "is not recognized as a valid link type")); 533 } 534 } 535 } 536 537 538 545 public int getUserType() 546 { 547 int utype = shortcut.getUserType(); 548 549 Debug.log( CLASS + myClass + ".getUserType() '" + utype + "'" ); 550 551 switch (utype) 552 { 553 case ShellLink.ALL_USERS: 554 utype = ALL_USERS; 555 break; 556 557 case ShellLink.CURRENT_USER: 558 utype = CURRENT_USER; 559 break; 560 } 561 562 return utype; 563 } 564 565 566 576 577 public void setUserType(int type) 578 { 579 Debug.log( CLASS + myClass + ".setUserType() '" + type + "'" ); 580 if (type == CURRENT_USER) 581 { 582 if (shortcut.getcurrentUserLinkPath().length() > 0) 583 { 584 shortcut.setUserType(ShellLink.CURRENT_USER); 585 } 586 } 587 else if (type == ALL_USERS) 588 { 589 if (shortcut.getallUsersLinkPath().length() > 0) 590 { 591 shortcut.setUserType(ShellLink.ALL_USERS); 592 } 593 } 594 } 595 596 597 602 public void save() throws Exception 603 { 604 605 shortcut.save(); 606 } 607 608 609 614 public int getHotkey() 615 { 616 int result = shortcut.getHotkey(); 617 Debug.log( CLASS + myClass + ".getHotkey() '" + result + "'" ); 618 return result; 619 } 620 621 622 632 public void setHotkey(int hotkey) 633 { 634 Debug.log( CLASS + myClass + ".setHotkey() '" + hotkey + "'" ); 635 shortcut.setHotkey(hotkey); 636 } 637 638 643 public String getProgramsFolder(int current_user) 644 { 645 646 int USER = 0; 647 648 if( current_user == Shortcut.CURRENT_USER ) 649 USER = ShellLink.CURRENT_USER; 650 651 else if( current_user == Shortcut.ALL_USERS ) 652 USER = ShellLink.ALL_USERS; 653 654 String result = null; 655 try 656 { 657 result = new String ( shortcut.getLinkPath(USER).getBytes( StringTool.getPlatformEncoding() ), StringTool.getPlatformEncoding() ); 658 } 659 catch (UnsupportedEncodingException e) 660 { 661 e.printStackTrace(); 663 } 664 Debug.log( CLASS + myClass + ".getProgramsFolder() '" + current_user + "', '" + result + "'" ); 665 return result; 666 } 667 } 668 669 670 | Popular Tags |