Skip to content

Commit

Permalink
general improvements
Browse files Browse the repository at this point in the history
removes unused variable from DownloadPretty.cs
removes "-" mark from ApplyDo.cs
check for failure on package index download on UpdateDo.cs
fixes on GetPackageIndexAsync so errors are reported correctly on console in PackageCacheIO.cs
general modernisation on AgsGetComponent for newer AGS.Plugin API on ContentDocument
  • Loading branch information
ericoporto committed Feb 1, 2020
1 parent aabacf4 commit ab80c48
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 31 deletions.
36 changes: 17 additions & 19 deletions agsget/agsget/EditorPlugin/AGS.Plugin.AgsGet/AgsGetComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,17 @@ public class AgsGetComponent : IEditorComponent
private const string COMPONENT_ID = "AgsGetComponent";
private const string CONTROL_ID_CONTEXT_MENU_OPTION = "AgsGetPluginOptionClick";
private const string CONTROL_ID_ROOT_NODE = "AgsGetPluginRoot";
private const string CONTROL_ID_MAIN_MENU_OPTION = "AgsGetPluginMainMenuOptionClick";
private const string NEW_MAIN_MENU_ID = "AgsGetPluginMenu";
private const string ICON_KEY = "AgsGetPluginIcon";

private IAGSEditor _editor;
private ContentDocument _pane;
private MenuCommands _mainMenuItems;
private readonly IAGSEditor _editor;
private readonly ContentDocument _pane;

public AgsGetComponent(IAGSEditor editor)
{
_editor = editor;
_editor.GUIController.RegisterIcon("AgsGetPluginIcon", GetIcon("PluginIcon.ico"));
_editor.GUIController.ProjectTree.AddTreeRoot(this, CONTROL_ID_ROOT_NODE, "AgsGet plugin", "AgsGetPluginIcon");
_pane = new ContentDocument(new AgsGetPane(editor), "Plugin pane", this);
_editor.GUIController.RegisterIcon(ICON_KEY, GetIcon("PluginIcon.ico"));
_editor.GUIController.ProjectTree.AddTreeRoot(this, CONTROL_ID_ROOT_NODE, "AgsGet plugin", ICON_KEY);
_pane = new ContentDocument(new AgsGetPane(editor), "AgsGet", this, ICON_KEY);
}

private Icon GetIcon(string fileName)
Expand Down Expand Up @@ -81,21 +79,21 @@ void IEditorComponent.GameSettingsChanged()

void IEditorComponent.ToXml(System.Xml.XmlTextWriter writer)
{
writer.WriteElementString("TextBoxContents", ((AgsGetPane)_pane.Control).TextBoxContents);
// writer.WriteElementString("TextBoxContents", ((AgsGetPane)_pane.Control).TextBoxContents);
}

void IEditorComponent.FromXml(System.Xml.XmlNode node)
{
if (node == null)
{
// node will be null if loading a 2.72 game or if
// the game hasn't used this plugin before
((AgsGetPane)_pane.Control).TextBoxContents = "Default text";
}
else
{
((AgsGetPane)_pane.Control).TextBoxContents = node.SelectSingleNode("TextBoxContents").InnerText;
}
//if (node == null)
//{
// // node will be null if loading a 2.72 game or if
// // the game hasn't used this plugin before
// ((AgsGetPane)_pane.Control).TextBoxContents = "";
//}
//else
//{
// ((AgsGetPane)_pane.Control).TextBoxContents = node.SelectSingleNode("TextBoxContents").InnerText;
//}
}

void IEditorComponent.EditorShutdown()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static async System.Threading.Tasks.Task<int> DoAsync(Action<string> writ
return 1;
}

writerMethod("-");
writerMethod("");
return 0;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ public static async System.Threading.Tasks.Task<int> DoAsync(Action<string> writ

//3.Downloads the index of packages to `./ ags_packages_cache / package_index`.
//If it already exists, overwrites it.
await PackageCacheIO.GetPackageIndexAsync(writerMethod, packageIndexURL);
if(!await PackageCacheIO.GetPackageIndexAsync(writerMethod, packageIndexURL))
{
writerMethod("Could not update package index.");
return 1;
}

writerMethod("Success.");
writerMethod("Index updated with success.");
return 0;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,20 @@ namespace AgsGetCore
// some commands are distributed on BaseFiles, maybe they need to be here and not there?
public class PackageCacheIO
{
public static async System.Threading.Tasks.Task GetPackageIndexAsync(Action<string> writerMethod, string packageIndexUrl)
public static async System.Threading.Tasks.Task<bool> GetPackageIndexAsync(Action<string> writerMethod, string packageIndexUrl)
{
var destinationFile = BaseFiles.GetIndexFilePath();
bool downloadResult;
if (string.IsNullOrEmpty(packageIndexUrl))
{
await DownloadPretty.FileAsync(writerMethod, Configuration.PackageIndexURL + "index/package_index.json", BaseFiles.GetIndexFilePath());
downloadResult = await DownloadPretty.FileAsync(writerMethod, Configuration.PackageIndexURL + "index/package_index.json", destinationFile);
}
else
{
await DownloadPretty.FileAsync(writerMethod, packageIndexUrl + "index/package_index.json", BaseFiles.GetIndexFilePath());
downloadResult = await DownloadPretty.FileAsync(writerMethod, packageIndexUrl + "index/package_index.json", destinationFile);
}
writerMethod("Index downloaded to:" + destinationFile);
return downloadResult;
}

public static bool PackageOnIndex(string packageName)
Expand Down Expand Up @@ -75,7 +79,7 @@ public static async System.Threading.Tasks.Task<bool> GetPackageAsync(Action<str
return false;
}

writerMethod("Package Downloaded to:" + destinationFile);
writerMethod("Package downloaded to:" + destinationFile);

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ public class DownloadPretty

writerMethod("Will download from:"+ url);

bool is_async = true;

if (writerMethod == Console.WriteLine) is_async = false;


var downloadTask = webClient.DownloadFileTaskAsync(
new Uri(url),
filename,
Expand Down

0 comments on commit ab80c48

Please sign in to comment.