Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing Disable and Re-enable not working fixes #167 #184

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 65 additions & 57 deletions application/GW2 Addon Manager/Backend/Updating/GenericUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private async Task StandaloneCheckUpdate()

if (addon_info.version_url != null)
{
using(var client = UpdateHelpers.GetClient())
using (var client = UpdateHelpers.GetClient())
{
latestVersion = client.DownloadString(addon_info.version_url);
}
Expand Down Expand Up @@ -108,9 +108,9 @@ private async Task Download(string url)
{
//this calls helper method to fetch filename if it is not exposed in URL
fileName = Path.Combine(
Path.GetTempPath(),
Path.GetTempPath(),
((addon_info.additional_flags != null && addon_info.additional_flags.Contains("obscured-filename")) ? GetFilenameFromWebServer(url) : Path.GetFileName(url))
);
);

if (File.Exists(fileName))
File.Delete(fileName);
Expand Down Expand Up @@ -171,7 +171,7 @@ private void Install()
File.Copy(Path.Combine(addon_expanded_path, addon_info.plugin_name), Path.Combine(Path.Combine(addon_install_path, "arcdps"), addon_info.plugin_name), true);
}


}
else
{
Expand All @@ -190,7 +190,7 @@ private void Install()
FileSystem.CopyFile(fileName, Path.Combine(Path.Combine(addon_install_path, "arcdps"), Path.GetFileName(fileName)), true);
}


}

//removing download from temp folder to avoid naming clashes
Expand All @@ -201,7 +201,7 @@ private void Install()
addonConfig.Version = latestVersion;
else
{
var newAddonConfig = new AddonData {Name = addon_name, Installed = true, Version = latestVersion};
var newAddonConfig = new AddonData { Name = addon_name, Installed = true, Version = latestVersion };
_configurationManager.UserConfig.AddonsList.Add(newAddonConfig);
}
_configurationManager.SaveConfiguration();
Expand All @@ -213,7 +213,7 @@ private void Install()
public void Disable()
{
var addonConfiguration =
_configurationManager.UserConfig.AddonsList.FirstOrDefault(a => a.Name == addon_info.addon_name);
_configurationManager.UserConfig.AddonsList.FirstOrDefault(a => a.Name == addon_info.folder_name);
if (addonConfiguration != null && addonConfiguration.Installed)
{
if (!Directory.Exists("Disabled Plugins"))
Expand All @@ -230,32 +230,37 @@ public void Disable()
}
else
{
//probably broken
if (!Directory.Exists(Path.Combine("Disabled Plugins", addon_info.folder_name)))
Directory.CreateDirectory(Path.Combine("Disabled Plugins", addon_info.folder_name));

if (addon_info.addon_name.Contains("BuildPad"))
var addonArc = _configurationManager.UserConfig.AddonsList.FirstOrDefault(a => a.Name == "arcdps");
if (!addonArc.Disabled)
{
string buildPadFileName = "";
string[] arcFiles = Directory.GetFiles(Path.Combine(Path.Combine(_configurationManager.UserConfig.GamePath, "addons"), "arcdps"));
//probably broken
if (!Directory.Exists(Path.Combine("Disabled Plugins", addon_info.folder_name)))
Directory.CreateDirectory(Path.Combine("Disabled Plugins", addon_info.folder_name));

//search for plugin name in arc folder
//TODO: Should break out of operation and give message if the plugin is not found.
foreach (string arcFileName in arcFiles)
if (arcFileName.Contains("buildpad"))
buildPadFileName = Path.GetFileName(arcFileName);

File.Move(
Path.Combine(Path.Combine(Path.Combine(_configurationManager.UserConfig.GamePath, "addons"), "arcdps"), buildPadFileName),
Path.Combine(Path.Combine("Disabled Plugins", addon_info.folder_name), buildPadFileName)
);
}
else
{
File.Move(
Path.Combine(Path.Combine(Path.Combine(_configurationManager.UserConfig.GamePath, "addons"), "arcdps"), addon_info.plugin_name),
Path.Combine(Path.Combine("Disabled Plugins", addon_info.folder_name), addon_info.plugin_name)
);
if (addon_info.addon_name.Contains("BuildPad"))
{
string buildPadFileName = "";
string[] arcFiles = Directory.GetFiles(Path.Combine(Path.Combine(_configurationManager.UserConfig.GamePath, "addons"), "arcdps"));

//search for plugin name in arc folder
//TODO: Should break out of operation and give message if the plugin is not found.
foreach (string arcFileName in arcFiles)
if (arcFileName.Contains("buildpad"))
buildPadFileName = Path.GetFileName(arcFileName);

File.Move(
Path.Combine(Path.Combine(Path.Combine(_configurationManager.UserConfig.GamePath, "addons"), "arcdps"), buildPadFileName),
Path.Combine(Path.Combine("Disabled Plugins", addon_info.folder_name), buildPadFileName)
);
}
else
{
File.Move(
Path.Combine(Path.Combine(Path.Combine(_configurationManager.UserConfig.GamePath, "addons"), "arcdps"), addon_info.plugin_name),
Path.Combine(Path.Combine("Disabled Plugins", addon_info.folder_name), addon_info.plugin_name)
);
}
}
}

Expand All @@ -269,7 +274,7 @@ public void Disable()
public void Enable()
{
var addonConfiguration =
_configurationManager.UserConfig.AddonsList.FirstOrDefault(a => a.Name == addon_info.addon_name);
_configurationManager.UserConfig.AddonsList.FirstOrDefault(a => a.Name == addon_info.folder_name);
if (addonConfiguration != null && addonConfiguration.Installed)
{
if (addonConfiguration.Disabled)
Expand All @@ -289,34 +294,37 @@ public void Enable()
if (!Directory.Exists(Path.Combine(Path.Combine(_configurationManager.UserConfig.GamePath, "addons"), "arcdps")))
Directory.CreateDirectory(Path.Combine(Path.Combine(_configurationManager.UserConfig.GamePath, "addons"), "arcdps"));

//buildpad compatibility check
if (!addon_info.addon_name.Contains("BuildPad"))
if (!File.Exists(Path.Combine(Path.Combine(Path.Combine(_configurationManager.UserConfig.GamePath, "addons"), "arcdps"), addon_info.plugin_name)))
{
//non-buildpad
File.Move(
Path.Combine(Path.Combine("Disabled Plugins", addon_info.folder_name), addon_info.plugin_name),
Path.Combine(Path.Combine(Path.Combine(_configurationManager.UserConfig.GamePath, "addons"), "arcdps"), addon_info.plugin_name)
);
//buildpad compatibility check
if (!addon_info.addon_name.Contains("BuildPad"))
{
//non-buildpad
File.Move(
Path.Combine(Path.Combine("Disabled Plugins", addon_info.folder_name), addon_info.plugin_name),
Path.Combine(Path.Combine(Path.Combine(_configurationManager.UserConfig.GamePath, "addons"), "arcdps"), addon_info.plugin_name)
);
}
else
{
//buildpad
string buildPadFileName = "";
string[] buildPadFiles = Directory.GetFiles(Path.Combine("Disabled Plugins", addon_info.folder_name));

foreach (string someFileName in buildPadFiles)
if (someFileName.Contains("buildpad"))
buildPadFileName = Path.GetFileName(someFileName);

File.Move(
Path.Combine(Path.Combine("Disabled Plugins", addon_info.folder_name), buildPadFileName),
Path.Combine(Path.Combine(Path.Combine(_configurationManager.UserConfig.GamePath, "addons"), "arcdps"), buildPadFileName)
);
}
}
else
{
//buildpad
string buildPadFileName = "";
string[] buildPadFiles = Directory.GetFiles(Path.Combine("Disabled Plugins", addon_info.folder_name));

foreach (string someFileName in buildPadFiles)
if (someFileName.Contains("buildpad"))
buildPadFileName = Path.GetFileName(someFileName);

File.Move(
Path.Combine(Path.Combine("Disabled Plugins", addon_info.folder_name), buildPadFileName),
Path.Combine(Path.Combine(Path.Combine(_configurationManager.UserConfig.GamePath, "addons"), "arcdps"), buildPadFileName)
);
}


}

addonConfiguration.Disabled = false;
_configurationManager.SaveConfiguration();
}
Expand All @@ -327,8 +335,8 @@ public void Enable()
public void Delete()
{
var addonConfiguration =
_configurationManager.UserConfig.AddonsList.FirstOrDefault(a => a.Name == addon_info.addon_name);
if (addonConfiguration != null && addonConfiguration.Installed)
_configurationManager.UserConfig.AddonsList.FirstOrDefault(a => a.Name == addon_info.folder_name);
if (addonConfiguration != null && addonConfiguration.Installed)
{
_configurationManager.UserConfig.AddonsList.Remove(addon_name);

Expand Down Expand Up @@ -395,7 +403,7 @@ void addon_DownloadProgressChanged(object sender, DownloadProgressChangedEventAr

void addon_DownloadCompleted(object sender, AsyncCompletedEventArgs e)
{

}
}
}