Skip to content

Commit

Permalink
2.2.5 Hotfix
Browse files Browse the repository at this point in the history
- Removed dependency on IWshRuntimeLibrary.dll. Was causing it to crash before even opening on some computers (Shouldn't happen... Might have something to do with .NET Core)

Updater:
- Fixed trying to start Account Switcher from a temp folder and failing because it's not there (strange...)
- Now attempts to start the program 3 times, incase it's still being written to on a slow computer
  • Loading branch information
TCNOco committed Jan 17, 2020
1 parent fb355ef commit dd7612d
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public partial class MainWindow : Window
List<string> fLoginUsersLines = new List<string>();
MainWindowViewModel MainViewmodel = new MainWindowViewModel();

//int version = 1;
int version = 2204;
int version = 1;
//int version = 2205;


// Settings will load later. Just defined here.
Expand Down Expand Up @@ -1343,16 +1343,42 @@ private void createShortcut(string location)
iconDirectory = Path.Combine(selflocation, "icon.ico"),
settingsLink = Path.Combine(location, "TcNo Account Switcher.lnk");

using (FileStream fs = new FileStream(iconDirectory, FileMode.Create))
Properties.Resources.icon.Save(fs);
if (!File.Exists(settingsLink))
{

using (FileStream fs = new FileStream(iconDirectory, FileMode.Create))
Properties.Resources.icon.Save(fs);


string[] Lines = {"set WshShell = WScript.CreateObject(\"WScript.Shell\")",
"set oShellLink = WshShell.CreateShortcut(\"" + settingsLink + "\")",
"oShellLink.TargetPath = \"" + selfexe + "\"",
"oShellLink.WindowStyle = 1",
"oShellLink.IconLocation = \"" + iconDirectory + "\"",
"oShellLink.Description = \"TcNo Account Switcher\"",
"oShellLink.WorkingDirectory = \"" + selflocation + "\"",
"oShellLink.Save()"
};
File.WriteAllLines("CreateShortcut.vbs", Lines);


IWshRuntimeLibrary.WshShellClass shellClass = new IWshRuntimeLibrary.WshShellClass();
IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shellClass.CreateShortcut(settingsLink);
shortcut.TargetPath = selfexe;
shortcut.IconLocation = iconDirectory;
shortcut.Arguments = "";
shortcut.Description = "TcNo Account Switcher";
shortcut.Save();
string result_string = "";
Process vbsProcess = new Process();

vbsProcess.StartInfo.FileName = "cscript";
vbsProcess.StartInfo.Arguments = "//nologo \"" + Path.Combine(selflocation, "CreateShortcut.vbs") + "\"";
vbsProcess.StartInfo.UseShellExecute = false;
vbsProcess.StartInfo.RedirectStandardOutput = true;
vbsProcess.StartInfo.CreateNoWindow = true;

vbsProcess.Start();
result_string = vbsProcess.StandardOutput.ReadToEnd();
vbsProcess.Close();

result_string = result_string.Replace("\r\n", "");
File.Delete("CreateShortcut.vbs");
MessageBox.Show("Shortcut created!\n\nLocation: " + location);
}
}
private void deleteShortcut(string location, bool delFolder)
{
Expand All @@ -1366,6 +1392,7 @@ private void deleteShortcut(string location, bool delFolder)
else
MessageBox.Show("Unable to delete folder because it's not empty: " + location);
}
MessageBox.Show("Shortcut deleted!");
}


Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<UseWPF>true</UseWPF>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Copyright>Copyright (c) TechNobo (Wesley Pyburn) 2019</Copyright>
<Version>2.2.3</Version>
<Version>2.2.5</Version>
<PackageProjectUrl>https://github.com/TcNobo/TcNo-Acc-Switcher</PackageProjectUrl>
<RepositoryUrl>https://github.com/TcNobo/TcNo-Acc-Switcher</RepositoryUrl>
<PackageIconUrl>https://github.com/TcNobo/TcNo-Acc-Switcher/raw/master/docs/img/TcNoAccSw-Icon-1000x1000.png</PackageIconUrl>
Expand Down Expand Up @@ -76,17 +76,6 @@
<None Remove="Resources\update64.7z" />
</ItemGroup>

<ItemGroup>
<COMReference Include="IWshRuntimeLibrary.dll">
<Guid>f935dc20-1cf0-11d0-adb9-00c04fd58a0b</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>0</VersionMinor>
<WrapperTool>tlbimp</WrapperTool>
<Lcid>0</Lcid>
<Isolated>false</Isolated>
</COMReference>
</ItemGroup>

<ItemGroup>
<Resource Include="Resources\7za.exe" />
<Resource Include="Resources\License.txt" />
Expand Down
39 changes: 32 additions & 7 deletions TCNO-Acc-Switcher-CSharp-WPF/TcNo-Acc-Switcher-Updater/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static void Main(string[] args)
wc.DownloadFile(downloadLink, downloadZip);

Console.WriteLine("Extracting Zip");
string ePath = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location),
string ePath = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName),
zPath = Path.Combine("Resources", "7za.exe");
try
{
Expand All @@ -63,6 +63,10 @@ static void Main(string[] args)
pro.UseShellExecute = false;
pro.RedirectStandardOutput = true;
pro.CreateNoWindow = true;

//Console.WriteLine(pro.FileName + " | " + pro.Arguments);
//Console.ReadLine();

Process x = Process.Start(pro);
x.WaitForExit();
}
Expand All @@ -75,16 +79,37 @@ static void Main(string[] args)
Console.WriteLine("");
Console.WriteLine("Starting TcNo Account Switcher");

string processName = "TcNo Account Switcher.exe";
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = processName;
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = true;
Process.Start(startInfo);
int attempts = 0;

while (attempts < 3)
{
try
{
attempts++;
string processName = "TcNo Account Switcher.exe";
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = processName;
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = true;

//Console.WriteLine(startInfo.FileName);
//Console.ReadLine();

Process.Start(startInfo);
break;
}
catch (Exception)
{
Console.WriteLine("Failed to start. Trying again in 3 seconds. (Attempt " + attempts + "/3)");
Thread.Sleep(3000);
}
}
Console.WriteLine("Closing in 2 seconds");
Thread.Sleep(3000);
Environment.Exit(1);
}
Console.WriteLine("Failed to update.");
Console.WriteLine("Please extract either x64.zip or x32.zip manually and start TcNo Account Switcher.exe");
}
static string versionToString(string version)
{
Expand Down

0 comments on commit dd7612d

Please sign in to comment.