| 49 | | bool ignoretransforms = false; |
|---|
| 50 | | bool ignorepatches = false; |
|---|
| 51 | | bool peruser = false; |
|---|
| 52 | | string command = ""; |
|---|
| 53 | | string packages = ""; |
|---|
| 54 | | |
|---|
| 55 | | foreach(string arg in args) |
|---|
| 56 | | { |
|---|
| 57 | | switch(arg.ToLower()) |
|---|
| 58 | | { |
|---|
| 59 | | case "--ignore-transforms": |
|---|
| 60 | | ignoretransforms = true; |
|---|
| 61 | | break; |
|---|
| 62 | | case "--ignore-patches": |
|---|
| 63 | | ignorepatches = true; |
|---|
| 64 | | break; |
|---|
| 65 | | case "--per-user": |
|---|
| 66 | | peruser = true; |
|---|
| | 49 | try |
|---|
| | 50 | { |
|---|
| | 51 | bool ignoretransforms = false; |
|---|
| | 52 | bool ignorepatches = false; |
|---|
| | 53 | bool peruser = false; |
|---|
| | 54 | string targetdir = ""; |
|---|
| | 55 | string command = ""; |
|---|
| | 56 | string packages = ""; |
|---|
| | 57 | |
|---|
| | 58 | foreach(string arg in args) |
|---|
| | 59 | { |
|---|
| | 60 | switch(arg.ToLower()) |
|---|
| | 61 | { |
|---|
| | 62 | case "--ignore-transforms": |
|---|
| | 63 | ignoretransforms = true; |
|---|
| | 64 | break; |
|---|
| | 65 | case "--ignore-patches": |
|---|
| | 66 | ignorepatches = true; |
|---|
| | 67 | break; |
|---|
| | 68 | case "--per-user": |
|---|
| | 69 | peruser = true; |
|---|
| | 70 | break; |
|---|
| | 71 | default: |
|---|
| | 72 | if(arg.ToLower().StartsWith("--target-dir")) |
|---|
| | 73 | { |
|---|
| | 74 | string[] parts = arg.ToLower().Split('='); |
|---|
| | 75 | if(parts[1] != null) |
|---|
| | 76 | targetdir=parts[1]; |
|---|
| | 77 | else |
|---|
| | 78 | { |
|---|
| | 79 | Console.Error.WriteLine("You must specify a directory when using --target-dir"); |
|---|
| | 80 | Usage(); |
|---|
| | 81 | return; |
|---|
| | 82 | } |
|---|
| | 83 | } |
|---|
| | 84 | else if(command == "") |
|---|
| | 85 | command = arg.ToLower(); |
|---|
| | 86 | else |
|---|
| | 87 | packages += arg + ","; |
|---|
| | 88 | break; |
|---|
| | 89 | } |
|---|
| | 90 | } |
|---|
| | 91 | |
|---|
| | 92 | if(command == "") |
|---|
| | 93 | { |
|---|
| | 94 | Console.Error.WriteLine("Error: no command specified"); |
|---|
| | 95 | Usage(); |
|---|
| | 96 | return; |
|---|
| | 97 | } |
|---|
| | 98 | |
|---|
| | 99 | if((command == "install" || command == "remove") && packages == "") |
|---|
| | 100 | { |
|---|
| | 101 | Console.Error.WriteLine("Error: no packages specified"); |
|---|
| | 102 | Usage(); |
|---|
| | 103 | return; |
|---|
| | 104 | } |
|---|
| | 105 | |
|---|
| | 106 | bool success = true; |
|---|
| | 107 | switch(command.ToLower()) |
|---|
| | 108 | { |
|---|
| | 109 | case "install": |
|---|
| | 110 | foreach(string package in packages.Split(',')) |
|---|
| | 111 | { |
|---|
| | 112 | success = Install(package, ignoretransforms, ignorepatches, peruser, targetdir) && success; |
|---|
| | 113 | } |
|---|
| | 114 | break; |
|---|
| | 115 | case "remove": |
|---|
| | 116 | Remove(packages.Split(',')); |
|---|
| | 117 | break; |
|---|
| | 118 | case "show": |
|---|
| | 119 | List(); |
|---|
| | 120 | break; |
|---|
| | 121 | case "upgrade": |
|---|
| | 122 | Upgrade(packages.Split(','), ignoretransforms, ignorepatches, peruser); |
|---|
| | 123 | break; |
|---|
| | 124 | case "dist-upgrade": |
|---|
| | 125 | DistUpgrade(packages.Split(','), ignoretransforms, ignorepatches, peruser, targetdir); |
|---|
| | 126 | break; |
|---|
| | 127 | case "update": |
|---|
| | 128 | Update(); |
|---|
| 69 | | if(command == "") |
|---|
| 70 | | command = arg.ToLower(); |
|---|
| 71 | | else |
|---|
| 72 | | packages += arg + ","; |
|---|
| 73 | | break; |
|---|
| 74 | | } |
|---|
| 75 | | } |
|---|
| 76 | | |
|---|
| 77 | | if(command == "") |
|---|
| 78 | | { |
|---|
| 79 | | Console.Error.WriteLine("Error: no command specified"); |
|---|
| 80 | | Usage(); |
|---|
| 81 | | return; |
|---|
| 82 | | } |
|---|
| 83 | | |
|---|
| 84 | | if((command == "install" || command == "remove") && packages == "") |
|---|
| 85 | | { |
|---|
| 86 | | Console.Error.WriteLine("Error: no packages specified"); |
|---|
| 87 | | Usage(); |
|---|
| 88 | | return; |
|---|
| 89 | | } |
|---|
| 90 | | |
|---|
| 91 | | bool success = true; |
|---|
| 92 | | switch(command.ToLower()) |
|---|
| 93 | | { |
|---|
| 94 | | case "install": |
|---|
| 95 | | foreach(string package in packages.Split(',')) |
|---|
| 96 | | { |
|---|
| 97 | | success = Install(package, ignoretransforms, ignorepatches, peruser) && success; |
|---|
| 98 | | } |
|---|
| 99 | | break; |
|---|
| 100 | | case "remove": |
|---|
| 101 | | Remove(packages.Split(',')); |
|---|
| 102 | | break; |
|---|
| 103 | | case "show": |
|---|
| 104 | | List(); |
|---|
| 105 | | break; |
|---|
| 106 | | case "upgrade": |
|---|
| 107 | | Upgrade(ignoretransforms, ignorepatches, peruser); |
|---|
| 108 | | break; |
|---|
| 109 | | case "dist-upgrade": |
|---|
| 110 | | DistUpgrade(ignoretransforms, ignorepatches, peruser); |
|---|
| 111 | | break; |
|---|
| 112 | | case "update": |
|---|
| 113 | | Update(); |
|---|
| 114 | | break; |
|---|
| 115 | | default: |
|---|
| 116 | | Usage(); |
|---|
| 117 | | break; |
|---|
| 118 | | } |
|---|
| 119 | | } |
|---|
| 120 | | |
|---|
| 121 | | private static bool Install(string p, bool ignoretransforms, bool ignorepatches, bool peruser) |
|---|
| | 131 | Usage(); |
|---|
| | 132 | break; |
|---|
| | 133 | } |
|---|
| | 134 | } |
|---|
| | 135 | catch(Exception e) |
|---|
| | 136 | { |
|---|
| | 137 | Console.Error.WriteLine( |
|---|
| | 138 | "Wipt has encountered a serious problem and is unable to continue. Please report this to SIGWin."); |
|---|
| | 139 | Console.Error.Write(e.Message + e.StackTrace); |
|---|
| | 140 | } |
|---|
| | 141 | } |
|---|
| | 142 | |
|---|
| | 143 | private static bool Install(string p, bool ignoretransforms, bool ignorepatches, bool peruser, string targetdir) |
|---|
| 365 | | public static void Upgrade(bool ignoretransforms, bool ignorepatches, bool peruser) |
|---|
| 366 | | { |
|---|
| 367 | | Product[] list = Library.GetAll(); |
|---|
| | 411 | public static void Upgrade(string[] products, bool ignoretransforms, bool ignorepatches, bool peruser) |
|---|
| | 412 | { |
|---|
| | 413 | Product[] list = new Product[0]; |
|---|
| | 414 | if(products.Length == 1 && products[0] == "") |
|---|
| | 415 | { |
|---|
| | 416 | list = Library.GetAll(); |
|---|
| | 417 | } |
|---|
| | 418 | else |
|---|
| | 419 | { |
|---|
| | 420 | foreach(string product in products) |
|---|
| | 421 | { |
|---|
| | 422 | if(product != "") |
|---|
| | 423 | { |
|---|
| | 424 | Product p = Library.GetProduct(product); |
|---|
| | 425 | if(p == null) |
|---|
| | 426 | { |
|---|
| | 427 | Console.Error.WriteLine("No such product {0}", product); |
|---|
| | 428 | } |
|---|
| | 429 | else |
|---|
| | 430 | { |
|---|
| | 431 | Product[] nl = new Product[list.Length + 1]; |
|---|
| | 432 | Array.Copy(list, nl, list.Length); |
|---|
| | 433 | nl[list.Length] = p; |
|---|
| | 434 | list = nl; |
|---|
| | 435 | } |
|---|
| | 436 | } |
|---|
| | 437 | } |
|---|
| | 438 | } |
|---|
| | 480 | Product[] list = new Product[0]; |
|---|
| | 481 | if(products.Length == 1 && products[0] == "") |
|---|
| | 482 | { |
|---|
| | 483 | list = Library.GetAll(); |
|---|
| | 484 | } |
|---|
| | 485 | else |
|---|
| | 486 | { |
|---|
| | 487 | foreach(string product in products) |
|---|
| | 488 | { |
|---|
| | 489 | if(product != "") |
|---|
| | 490 | { |
|---|
| | 491 | Product p = Library.GetProduct(product); |
|---|
| | 492 | if(p == null) |
|---|
| | 493 | { |
|---|
| | 494 | Console.Error.WriteLine("No such product {0}", product); |
|---|
| | 495 | } |
|---|
| | 496 | else |
|---|
| | 497 | { |
|---|
| | 498 | Product[] nl = new Product[list.Length + 1]; |
|---|
| | 499 | Array.Copy(list, nl, list.Length); |
|---|
| | 500 | nl[list.Length] = p; |
|---|
| | 501 | list = nl; |
|---|
| | 502 | } |
|---|
| | 503 | } |
|---|
| | 504 | } |
|---|
| | 505 | } |
|---|
| | 506 | |
|---|
| | 507 | foreach(Product p in list) |
|---|
| | 508 | { |
|---|
| | 509 | if(IsInstalled(p.name) && !IsInstalled(p.name, p.stableVersion, new Version("99.99.9999"))) |
|---|
| | 510 | { |
|---|
| | 511 | Install(p.name + "=" + p.stableVersion.ToString(), ignoretransforms, ignorepatches, peruser, targetdir); |
|---|
| | 512 | } |
|---|
| | 513 | } |
|---|
| | 514 | } |
|---|
| | 515 | catch(WiptException e) |
|---|
| | 516 | { |
|---|
| | 517 | Console.Error.Write(e.Message); |
|---|
| | 518 | } |
|---|
| | 519 | } |
|---|
| | 520 | |
|---|
| | 521 | public static void List() |
|---|
| | 522 | { |
|---|
| | 523 | try |
|---|
| | 524 | { |
|---|
| 401 | | foreach(Product p in list) |
|---|
| 402 | | { |
|---|
| 403 | | if(IsInstalled(p.name) && !IsInstalled(p.name, p.stableVersion, new Version("99.99.9999"))) |
|---|
| 404 | | { |
|---|
| 405 | | Install(p.name + "=" + p.stableVersion.ToString(), ignoretransforms, ignorepatches, peruser); |
|---|
| 406 | | } |
|---|
| | 526 | if(list.Length > 0) |
|---|
| | 527 | { |
|---|
| | 528 | Array.Sort(list); |
|---|
| | 529 | foreach(Product p in list) |
|---|
| | 530 | { |
|---|
| | 531 | Console.WriteLine("\n" + p.name); |
|---|
| | 532 | if(p.packages.Length > 0) |
|---|
| | 533 | { |
|---|
| | 534 | Array.Sort(p.packages); |
|---|
| | 535 | foreach(Package k in p.packages) |
|---|
| | 536 | { |
|---|
| | 537 | string installstring=""; |
|---|
| | 538 | if(p.stableVersion == k.version) |
|---|
| | 539 | installstring = "(stable)"; |
|---|
| | 540 | if(ApplicationDatabase.getProductState(k.productCode) |
|---|
| | 541 | == InstallState.Default) |
|---|
| | 542 | installstring += "(installed)"; |
|---|
| | 543 | Console.WriteLine(" v{0} {1}", k.version.ToString(), installstring); |
|---|
| | 544 | } |
|---|
| | 545 | } |
|---|
| | 546 | else |
|---|
| | 547 | { |
|---|
| | 548 | Console.WriteLine(" [No packages found]"); |
|---|
| | 549 | } |
|---|
| | 550 | } |
|---|
| | 551 | } |
|---|
| | 552 | else |
|---|
| | 553 | { |
|---|
| | 554 | Console.Error.WriteLine("No packages found in database."); |
|---|
| 411 | | Console.Error.Write(e.Message); |
|---|
| 412 | | } |
|---|
| 413 | | } |
|---|
| 414 | | |
|---|
| 415 | | public static void List() |
|---|
| 416 | | { |
|---|
| 417 | | try |
|---|
| 418 | | { |
|---|
| 419 | | Product[] list = Library.GetAll(); |
|---|
| 420 | | Array.Sort(list); |
|---|
| 421 | | foreach(Product p in list) |
|---|
| 422 | | { |
|---|
| 423 | | Console.WriteLine("\n" + p.name); |
|---|
| 424 | | Array.Sort(p.packages); |
|---|
| 425 | | foreach(Package k in p.packages) |
|---|
| 426 | | { |
|---|
| 427 | | string installstring=""; |
|---|
| 428 | | if(p.stableVersion == k.version) |
|---|
| 429 | | installstring = "(stable)"; |
|---|
| 430 | | if(ApplicationDatabase.getProductState(k.productCode) |
|---|
| 431 | | == InstallState.Default) |
|---|
| 432 | | installstring += "(installed)"; |
|---|
| 433 | | Console.WriteLine("\tv{0} {1}", k.version.ToString(), installstring); |
|---|
| 434 | | } |
|---|
| 435 | | } |
|---|
| 436 | | } |
|---|
| 437 | | catch(WiptException e) |
|---|
| 438 | | { |
|---|
| 455 | | i++; |
|---|
| 456 | | } |
|---|
| 457 | | } |
|---|
| 458 | | |
|---|
| 459 | | return Guid.Empty; |
|---|
| 460 | | } |
|---|
| 461 | | |
|---|
| 462 | | private static bool IsInstalled(string product) |
|---|
| 463 | | { |
|---|
| 464 | | bool installed = false; |
|---|
| 465 | | Object obj = Library.GetProduct(product); |
|---|
| 466 | | |
|---|
| 467 | | if(obj == null || obj is Patch) |
|---|
| 468 | | { |
|---|
| 469 | | installed = false; |
|---|
| 470 | | } |
|---|
| 471 | | else if(obj is Product) |
|---|
| 472 | | { |
|---|
| 473 | | Product p = (Product)obj; |
|---|
| | 593 | int i = 0; |
|---|
| | 594 | Guid productCode; |
|---|
| | 595 | while((productCode = ApplicationDatabase.findProductByUpgradeCode(p.upgradeCode, i++)) != Guid.Empty) |
|---|
| | 596 | { |
|---|
| | 597 | InstallState state = ApplicationDatabase.getProductState(productCode); |
|---|
| | 598 | if(!(state == InstallState.Removed || state == InstallState.Absent || state == InstallState.Unknown)) |
|---|
| | 599 | { |
|---|
| | 600 | installed = true; |
|---|
| | 601 | } |
|---|
| | 602 | } |
|---|
| | 603 | } |
|---|
| | 604 | |
|---|
| | 605 | return installed; |
|---|
| | 606 | } |
|---|
| | 607 | |
|---|
| | 608 | private static bool IsInstalled(string product, Version minVersion, Version maxVersion) |
|---|
| | 609 | { |
|---|
| | 610 | Product p = Library.GetProduct(product); |
|---|
| | 611 | if(p == null) |
|---|
| | 612 | { |
|---|
| | 613 | return false; |
|---|
| | 614 | } |
|---|
| 477 | | while((productCode = ApplicationDatabase.findProductByUpgradeCode(p.upgradeCode, i++)) != Guid.Empty) |
|---|
| 478 | | { |
|---|
| 479 | | InstallState state = ApplicationDatabase.getProductState(productCode); |
|---|
| 480 | | if(!(state == InstallState.Removed || state == InstallState.Absent || state == InstallState.Unknown)) |
|---|
| 481 | | { |
|---|
| 482 | | installed = true; |
|---|
| 483 | | } |
|---|
| 484 | | } |
|---|
| 485 | | } |
|---|
| 486 | | |
|---|
| 487 | | return installed; |
|---|
| 488 | | } |
|---|
| 489 | | |
|---|
| 490 | | private static bool IsInstalled(string product, Version minVersion, Version maxVersion) |
|---|
| 491 | | { |
|---|
| 492 | | Object obj = Library.GetProduct(product); |
|---|
| 493 | | if(obj == null || !(obj is Product)) |
|---|
| 494 | | { |
|---|
| 495 | | return false; |
|---|
| 496 | | } |
|---|
| 497 | | |
|---|
| 498 | | Product p = (Product)obj; |
|---|
| 499 | | |
|---|
| 500 | | int i = 0; |
|---|
| 501 | | Guid productCode; |
|---|