mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-03 14:34:08 +02:00
Finish all TweetDeck migration features (kill process, change pinned taskbar lnk, fix oversights)
This commit is contained in:
parent
226e9bf228
commit
a48ce84756
42
Migration/Helpers/LnkEditor.cs
Normal file
42
Migration/Helpers/LnkEditor.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using Shell32;
|
||||
using System.IO;
|
||||
|
||||
namespace TweetDick.Migration.Helpers{
|
||||
sealed class LnkEditor{
|
||||
private readonly ShellLinkObject obj;
|
||||
|
||||
public LnkEditor(string file){
|
||||
try{
|
||||
Shell shell = new Shell();
|
||||
Folder folder = shell.NameSpace(Path.GetDirectoryName(file));
|
||||
FolderItem item = folder.Items().Item(Path.GetFileName(file));
|
||||
|
||||
obj = item.GetLink as ShellLinkObject;
|
||||
}catch(Exception){
|
||||
obj = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetComment(string newComment){
|
||||
if (obj == null)return;
|
||||
obj.Description = newComment;
|
||||
}
|
||||
|
||||
public void SetPath(string newPath){
|
||||
if (obj == null)return;
|
||||
obj.Path = newPath;
|
||||
obj.SetIconLocation(newPath,0);
|
||||
}
|
||||
|
||||
public void SetWorkingDirectory(string newWorkingDirectory){
|
||||
if (obj == null)return;
|
||||
obj.WorkingDirectory = newWorkingDirectory;
|
||||
}
|
||||
|
||||
public void Save(){
|
||||
if (obj == null)return;
|
||||
obj.Save();
|
||||
}
|
||||
}
|
||||
}
|
15
Migration/Helpers/ProgramProcessSearch.cs
Normal file
15
Migration/Helpers/ProgramProcessSearch.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
|
||||
namespace TweetDick.Migration.Helpers{
|
||||
static class ProgramProcessSearch{
|
||||
public static Process FindProcessWithWindowByName(string name){
|
||||
try{
|
||||
return Process.GetProcessesByName(name).FirstOrDefault(process => process.MainWindowHandle != IntPtr.Zero);
|
||||
}catch(Exception){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using TweetDick.Core;
|
||||
@ -63,7 +64,7 @@ private static bool BeginMigration(MigrationDecision decision, Action<Exception>
|
||||
CopyFile("Local Storage"+Path.DirectorySeparatorChar+"https_tweetdeck.twitter.com_0.localstorage");
|
||||
CopyFile("Local Storage"+Path.DirectorySeparatorChar+"https_tweetdeck.twitter.com_0.localstorage-journal");
|
||||
|
||||
if (decision == MigrationDecision.Migrate){
|
||||
if (decision == MigrationDecision.Migrate || decision == MigrationDecision.MigratePurge){
|
||||
Directory.Delete(TweetDeckPath,true);
|
||||
|
||||
try{
|
||||
@ -74,6 +75,32 @@ private static bool BeginMigration(MigrationDecision decision, Action<Exception>
|
||||
}
|
||||
|
||||
if (decision == MigrationDecision.MigratePurge){
|
||||
// kill process if running
|
||||
Process runningProcess = ProgramProcessSearch.FindProcessWithWindowByName("TweetDeck");
|
||||
|
||||
if (runningProcess != null){
|
||||
runningProcess.CloseMainWindow();
|
||||
|
||||
for(int wait = 0; wait < 100 && !runningProcess.HasExited; wait++){ // 10 seconds
|
||||
runningProcess.Refresh();
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
|
||||
runningProcess.Close();
|
||||
}
|
||||
|
||||
// update the pinned taskbar lnk if exists
|
||||
string linkFile = Path.Combine(Environment.ExpandEnvironmentVariables(@"%APPDATA%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar"),"TweetDeck.lnk");
|
||||
|
||||
if (File.Exists(linkFile)){
|
||||
LnkEditor lnk = new LnkEditor(linkFile);
|
||||
lnk.SetPath(Application.ExecutablePath);
|
||||
lnk.SetWorkingDirectory(Environment.CurrentDirectory);
|
||||
lnk.SetComment("TweetDick"); // TODO add a tagline
|
||||
lnk.Save();
|
||||
}
|
||||
|
||||
// uninstall in the background
|
||||
string guid = ProgramRegistrySearch.FindByDisplayName("TweetDeck");
|
||||
|
||||
if (guid != null){
|
||||
@ -83,6 +110,8 @@ private static bool BeginMigration(MigrationDecision decision, Action<Exception>
|
||||
uninstaller.WaitForExit();
|
||||
}
|
||||
}
|
||||
|
||||
// migration finished like a boss
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -103,6 +103,8 @@
|
||||
<Compile Include="Migration\FormMigrationQuestion.Designer.cs">
|
||||
<DependentUpon>FormMigrationQuestion.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Migration\Helpers\LnkEditor.cs" />
|
||||
<Compile Include="Migration\Helpers\ProgramProcessSearch.cs" />
|
||||
<Compile Include="Migration\MigrationDecision.cs" />
|
||||
<Compile Include="Migration\MigrationManager.cs" />
|
||||
<Compile Include="Migration\Helpers\ProgramRegistrySearch.cs" />
|
||||
@ -133,6 +135,17 @@
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<COMReference Include="Shell32">
|
||||
<Guid>{50A7E9B0-70EF-11D1-B75A-00A0C90564FE}</Guid>
|
||||
<VersionMajor>1</VersionMajor>
|
||||
<VersionMinor>0</VersionMinor>
|
||||
<Lcid>0</Lcid>
|
||||
<WrapperTool>tlbimp</WrapperTool>
|
||||
<Isolated>False</Isolated>
|
||||
<EmbedInteropTypes>True</EmbedInteropTypes>
|
||||
</COMReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="packages\cef.redist.x86.3.2526.1362\build\cef.redist.x86.targets" Condition="Exists('packages\cef.redist.x86.3.2526.1362\build\cef.redist.x86.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
|
Loading…
Reference in New Issue
Block a user