1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-08 02:34:06 +02:00

Add an untested Migrate & Purge option to the migration Form

This commit is contained in:
chylex 2016-04-09 21:44:55 +02:00
parent 66e83f9056
commit 3db2d11af7
6 changed files with 106 additions and 24 deletions

View File

@ -25,9 +25,10 @@ protected override void Dispose(bool disposing) {
private void InitializeComponent() {
this.btnIgnore = new System.Windows.Forms.Button();
this.panelButtons = new System.Windows.Forms.FlowLayoutPanel();
this.btnAskLater = new System.Windows.Forms.Button();
this.btnCopy = new System.Windows.Forms.Button();
this.btnMigrate = new System.Windows.Forms.Button();
this.btnAskLater = new System.Windows.Forms.Button();
this.btnMigrateUninstall = new System.Windows.Forms.Button();
this.labelQuestion = new TweetDick.Core.RichTextLabel();
this.panelButtons.SuspendLayout();
this.SuspendLayout();
@ -54,12 +55,27 @@ private void InitializeComponent() {
this.panelButtons.Controls.Add(this.btnIgnore);
this.panelButtons.Controls.Add(this.btnCopy);
this.panelButtons.Controls.Add(this.btnMigrate);
this.panelButtons.Controls.Add(this.btnMigrateUninstall);
this.panelButtons.FlowDirection = System.Windows.Forms.FlowDirection.RightToLeft;
this.panelButtons.Location = new System.Drawing.Point(12, 71);
this.panelButtons.Location = new System.Drawing.Point(12, 101);
this.panelButtons.Name = "panelButtons";
this.panelButtons.Size = new System.Drawing.Size(480, 23);
this.panelButtons.TabIndex = 0;
//
// btnAskLater
//
this.btnAskLater.AutoSize = true;
this.btnAskLater.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.btnAskLater.Location = new System.Drawing.Point(412, 0);
this.btnAskLater.Margin = new System.Windows.Forms.Padding(3, 0, 0, 0);
this.btnAskLater.Name = "btnAskLater";
this.btnAskLater.Padding = new System.Windows.Forms.Padding(3, 0, 3, 0);
this.btnAskLater.Size = new System.Drawing.Size(68, 23);
this.btnAskLater.TabIndex = 0;
this.btnAskLater.Text = "Ask Later";
this.btnAskLater.UseVisualStyleBackColor = true;
this.btnAskLater.Click += new System.EventHandler(this.btnAskLater_Click);
//
// btnCopy
//
this.btnCopy.AutoSize = true;
@ -79,7 +95,7 @@ private void InitializeComponent() {
this.btnMigrate.AutoSize = true;
this.btnMigrate.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.btnMigrate.Location = new System.Drawing.Point(239, 0);
this.btnMigrate.Margin = new System.Windows.Forms.Padding(0, 0, 3, 0);
this.btnMigrate.Margin = new System.Windows.Forms.Padding(3, 0, 3, 0);
this.btnMigrate.Name = "btnMigrate";
this.btnMigrate.Padding = new System.Windows.Forms.Padding(3, 0, 3, 0);
this.btnMigrate.Size = new System.Drawing.Size(58, 23);
@ -88,19 +104,19 @@ private void InitializeComponent() {
this.btnMigrate.UseVisualStyleBackColor = true;
this.btnMigrate.Click += new System.EventHandler(this.btnMigrate_Click);
//
// btnAskLater
// btnMigrateUninstall
//
this.btnAskLater.AutoSize = true;
this.btnAskLater.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.btnAskLater.Location = new System.Drawing.Point(412, 0);
this.btnAskLater.Margin = new System.Windows.Forms.Padding(3, 0, 0, 0);
this.btnAskLater.Name = "btnAskLater";
this.btnAskLater.Padding = new System.Windows.Forms.Padding(3, 0, 3, 0);
this.btnAskLater.Size = new System.Drawing.Size(68, 23);
this.btnAskLater.TabIndex = 0;
this.btnAskLater.Text = "Ask Later";
this.btnAskLater.UseVisualStyleBackColor = true;
this.btnAskLater.Click += new System.EventHandler(this.btnAskLater_Click);
this.btnMigrateUninstall.AutoSize = true;
this.btnMigrateUninstall.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.btnMigrateUninstall.Location = new System.Drawing.Point(135, 0);
this.btnMigrateUninstall.Margin = new System.Windows.Forms.Padding(0, 0, 3, 0);
this.btnMigrateUninstall.Name = "btnMigrateUninstall";
this.btnMigrateUninstall.Padding = new System.Windows.Forms.Padding(3, 0, 3, 0);
this.btnMigrateUninstall.Size = new System.Drawing.Size(98, 23);
this.btnMigrateUninstall.TabIndex = 4;
this.btnMigrateUninstall.Text = "Migrate && Purge";
this.btnMigrateUninstall.UseVisualStyleBackColor = true;
this.btnMigrateUninstall.Click += new System.EventHandler(this.btnMigrateUninstall_Click);
//
// labelQuestion
//
@ -113,22 +129,22 @@ private void InitializeComponent() {
this.labelQuestion.Name = "labelQuestion";
this.labelQuestion.ReadOnly = true;
this.labelQuestion.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.None;
this.labelQuestion.Size = new System.Drawing.Size(443, 56);
this.labelQuestion.Size = new System.Drawing.Size(443, 86);
this.labelQuestion.TabIndex = 2;
this.labelQuestion.TabStop = false;
this.labelQuestion.Text = "";
//
// FormMigration
// FormMigrationQuestion
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(504, 106);
this.ClientSize = new System.Drawing.Size(504, 136);
this.Controls.Add(this.labelQuestion);
this.Controls.Add(this.panelButtons);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "FormMigration";
this.Name = "FormMigrationQuestion";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "TweetDeck Migration";
this.panelButtons.ResumeLayout(false);
@ -145,5 +161,6 @@ private void InitializeComponent() {
private System.Windows.Forms.Button btnMigrate;
private Core.RichTextLabel labelQuestion;
private System.Windows.Forms.Button btnAskLater;
private System.Windows.Forms.Button btnMigrateUninstall;
}
}

View File

@ -10,7 +10,7 @@ partial class FormMigrationQuestion : Form{
public FormMigrationQuestion(){
InitializeComponent();
labelQuestion.Rtf = RichTextLabel.Wrap(@"Hey there, I found some TweetDeck data! Do you want to \b Migrate\b0 it and delete the old data folder, \b Copy\b0 it and keep the folder, \b Ignore\b0 the request forever, or do you need some more time for the decision?");
labelQuestion.Rtf = RichTextLabel.Wrap(@"Hey there, I found some TweetDeck data! Do you want to \b Migrate\b0 it and delete the old data folder, \b Copy\b0 it and keep the folder, \b Ignore\b0 the request forever, or do you need some more time for the decision?\par You may also \b Migrate & Purge\b0 which uninstalls TweetDeck too!");
}
protected override void OnPaint(PaintEventArgs e){
@ -18,6 +18,10 @@ protected override void OnPaint(PaintEventArgs e){
base.OnPaint(e);
}
private void btnMigrateUninstall_Click(object sender, EventArgs e){
Close(MigrationDecision.MigratePurge);
}
private void btnMigrate_Click(object sender, EventArgs e){
Close(MigrationDecision.Migrate);
}

View File

@ -5,6 +5,11 @@ enum MigrationDecision{
/// </summary>
Migrate,
/// <summary>
/// Does exactly what <see cref="Migrate"/> does, but also silently uninstalls TweetDeck.
/// </summary>
MigratePurge,
/// <summary>
/// Copies the important files without deleting the TweetDeck folder.
/// </summary>

View File

@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using System.Windows.Forms;
@ -15,6 +16,7 @@ public static void Run(){
MigrationDecision decision = formQuestion.ShowDialog() == DialogResult.OK ? formQuestion.Decision : MigrationDecision.AskLater;
switch(decision){
case MigrationDecision.MigratePurge:
case MigrationDecision.Migrate:
case MigrationDecision.Copy:
FormBackgroundWork formWait = new FormBackgroundWork();
@ -45,7 +47,7 @@ public static void Run(){
}
private static bool BeginMigration(MigrationDecision decision, Action<Exception> onFinished){
if (decision != MigrationDecision.Migrate && decision != MigrationDecision.Copy){
if (decision != MigrationDecision.MigratePurge && decision != MigrationDecision.Migrate && decision != MigrationDecision.Copy){
return false;
}
@ -69,11 +71,21 @@ private static bool BeginMigration(MigrationDecision decision, Action<Exception>
// most likely not empty, ignore
}
}
if (decision == MigrationDecision.MigratePurge){
string guid = ProgramRegistrySearch.FindByDisplayName("TweetDeck");
if (guid != null){
Process uninstaller = Process.Start("msiexec.exe","/x"+guid+" /quiet /qn");
if (uninstaller != null){
uninstaller.WaitForExit();
}
}
}
});
task.ContinueWith(originalTask => {
onFinished(originalTask.Exception);
},TaskContinuationOptions.ExecuteSynchronously);
task.ContinueWith(originalTask => onFinished(originalTask.Exception),TaskContinuationOptions.ExecuteSynchronously);
task.Start();
return true;

View File

@ -0,0 +1,43 @@
using Microsoft.Win32;
using System;
using System.Linq;
namespace TweetDick.Migration{
static class ProgramRegistrySearch{
public static string FindByDisplayName(string displayName){
Predicate<RegistryKey> predicate = key => displayName.Equals(key.GetValue("DisplayName") as string,StringComparison.OrdinalIgnoreCase);
string guid;
return FindMatchingSubKey(Registry.LocalMachine,@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall",predicate,out guid) ||
FindMatchingSubKey(Registry.LocalMachine,@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall",predicate,out guid) ||
FindMatchingSubKey(Registry.CurrentUser,@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall",predicate,out guid)
? guid : null;
}
private static bool FindMatchingSubKey(RegistryKey keyHandle, string path, Predicate<RegistryKey> predicate, out string guid){
string outputId = null;
try{
RegistryKey parentKey = keyHandle.OpenSubKey(path,false);
if (parentKey == null)throw new InvalidOperationException();
foreach(RegistryKey subKey in parentKey.GetSubKeyNames().Select(subName => parentKey.OpenSubKey(subName,false)).Where(subKey => subKey != null)){
if (predicate(subKey)){
outputId = subKey.Name.Substring(subKey.Name.LastIndexOf('\\')+1);
subKey.Close();
break;
}
subKey.Close();
}
parentKey.Close();
}catch(Exception){
guid = null;
return false;
}
return (guid = outputId) != null;
}
}
}

View File

@ -105,6 +105,7 @@
</Compile>
<Compile Include="Migration\MigrationDecision.cs" />
<Compile Include="Migration\MigrationManager.cs" />
<Compile Include="Migration\ProgramRegistrySearch.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<None Include="Configuration\app.config" />