Skip to content

Commit d1159d6

Browse files
committed
add and remove package working with dependency resolution.
1 parent b19f73f commit d1159d6

9 files changed

Lines changed: 430 additions & 22 deletions

File tree

agsget/agsget/EditorPlugin/AGS.Plugin.AgsGet/AgsGet.Designer.cs

Lines changed: 55 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

agsget/agsget/EditorPlugin/AGS.Plugin.AgsGet/AgsGetComponent.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ public class AgsGetComponent : IEditorComponent
2121

2222
private readonly IAGSEditor _editor;
2323
private readonly ContentDocument _pane;
24+
private readonly AgsGetPane _agsGetPane;
2425

2526
public AgsGetComponent(IAGSEditor editor)
2627
{
2728
_editor = editor;
2829
_editor.GUIController.RegisterIcon(ICON_KEY, GetIcon("PluginIcon.ico"));
2930
_editor.GUIController.ProjectTree.AddTreeRoot(this, CONTROL_ID_ROOT_NODE, "AgsGet plugin", ICON_KEY);
30-
_pane = new ContentDocument(new AgsGetPane(editor), "AgsGet", this, ICON_KEY);
31+
_agsGetPane = new AgsGetPane(editor);
32+
_pane = new ContentDocument(_agsGetPane, "AgsGet", this, ICON_KEY);
3133
}
3234

3335
private Icon GetIcon(string fileName)
@@ -56,6 +58,7 @@ void IEditorComponent.CommandClick(string controlID)
5658
else if (controlID == CONTROL_ID_ROOT_NODE)
5759
{
5860
_editor.GUIController.AddOrShowPane(_pane);
61+
_agsGetPane.PanelReload();
5962
}
6063
}
6164

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace AgsGetCore.Actions
8+
{
9+
class AddPackageDo
10+
{
11+
public static async System.Threading.Tasks.Task<int> DoAsync(Action<string> writerMethod, string changeRunDir, string packageName)
12+
{
13+
BaseFiles.SetRunDirectory(changeRunDir);
14+
15+
//1. If no PACKAGE_NAME is provided, exit with error.
16+
// maybe the required keyword protects and we don't need this
17+
if (string.IsNullOrEmpty(packageName) == true)
18+
{
19+
writerMethod("No Package Specified, will do nothing.");
20+
return 1;
21+
}
22+
23+
//2. Check if the command is run from a folder containing a valid Game.agf project. If not, exit with error.
24+
if (!GameAgfIO.Valid())
25+
{
26+
writerMethod("Not an AGS Game root directory.");
27+
writerMethod("You can only get packages for an AGS Game project.");
28+
return 1;
29+
}
30+
31+
//3. Check if a package index exists on `./ags_packages_cache/package_index`, if not, it runs the functionality from `agsget update`.
32+
if (!BaseFiles.ExistsIndexFile())
33+
{
34+
//Update.2.If it is, creates a folder `./ ags_packages_cache /` on the directory if it doesn't exist.
35+
BaseFiles.CreatePackageDirIfDoesntExist();
36+
37+
//Update.3.Downloads the index of packages to `./ ags_packages_cache / package_index`.
38+
//If it already exists, overwrites it.
39+
await PackageCacheIO.GetPackageIndexAsync(writerMethod, null);
40+
}
41+
42+
// Check if index is really here
43+
if (!BaseFiles.ExistsIndexFile())
44+
{
45+
writerMethod("No package index found, it's possible a download failed due to connection error.");
46+
return 1;
47+
}
48+
49+
//4.Check if PACKAGE_NAME exists on `./ ags_packages_cache / package_index`, if not, exit with error.
50+
if (!PackageCacheIO.PackageOnIndex(packageName))
51+
{
52+
writerMethod(string.Format("Package {0} not found on package index.", packageName));
53+
writerMethod("If you are sure you spelled correctly, try updating your local package index.");
54+
return 1;
55+
}
56+
57+
if (!IntentDescriptor.AddPackage(packageName))
58+
{
59+
writerMethod("An error occurred when generating the Manifest File.");
60+
return 1;
61+
}
62+
63+
if (!PackageLocker.Lock())
64+
{
65+
writerMethod("An error occurred when generating the Lock File.");
66+
return 1;
67+
}
68+
69+
writerMethod(string.Format("Package {0} add to manifest and lock file successfully generated.",packageName));
70+
return 0;
71+
}
72+
}
73+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace AgsGetCore.Actions
8+
{
9+
class RemovePackageDo
10+
{
11+
public static async System.Threading.Tasks.Task<int> DoAsync(Action<string> writerMethod, string changeRunDir, string packageName)
12+
{
13+
BaseFiles.SetRunDirectory(changeRunDir);
14+
15+
//1. If no PACKAGE_NAME is provided, exit with error.
16+
// maybe the required keyword protects and we don't need this
17+
if (string.IsNullOrEmpty(packageName) == true)
18+
{
19+
writerMethod("No Package Specified, will do nothing.");
20+
return 1;
21+
}
22+
23+
//2. Check if the command is run from a folder containing a valid Game.agf project. If not, exit with error.
24+
if (!GameAgfIO.Valid())
25+
{
26+
writerMethod("Not an AGS Game root directory.");
27+
writerMethod("You can only get packages for an AGS Game project.");
28+
return 1;
29+
}
30+
31+
//3. Check if a package index exists on `./ags_packages_cache/package_index`, if not, it runs the functionality from `agsget update`.
32+
if (!BaseFiles.ExistsIndexFile())
33+
{
34+
//Update.2.If it is, creates a folder `./ ags_packages_cache /` on the directory if it doesn't exist.
35+
BaseFiles.CreatePackageDirIfDoesntExist();
36+
37+
//Update.3.Downloads the index of packages to `./ ags_packages_cache / package_index`.
38+
//If it already exists, overwrites it.
39+
await PackageCacheIO.GetPackageIndexAsync(writerMethod, null);
40+
}
41+
42+
// Check if index is really here
43+
if (!BaseFiles.ExistsIndexFile())
44+
{
45+
writerMethod("No package index found, it's possible a download failed due to connection error.");
46+
return 1;
47+
}
48+
49+
if (!IntentDescriptor.RemovePackage(packageName))
50+
{
51+
writerMethod("An error occurred when generating the Manifest File.");
52+
return 1;
53+
}
54+
55+
if (!PackageLocker.Lock())
56+
{
57+
writerMethod("An error occurred when generating the Lock File.");
58+
return 1;
59+
}
60+
61+
writerMethod(string.Format("Package {0} removed from manifest and lock file successfully generated.", packageName));
62+
return 0;
63+
}
64+
}
65+
}

agsget/agsget/EditorPlugin/AGS.Plugin.AgsGet/AgsGetCore/AgsGetCore.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,25 @@ public static async System.Threading.Tasks.Task<List<Package>> ListAllAsync(Acti
3737
{
3838
return await ListDo.DoAsync(writerMethod, changeRunDir, packageIndexURL, 0, 0);
3939
}
40+
41+
public static async System.Threading.Tasks.Task<int> AddPackageAsync(Action<string> writerMethod, string changeRunDir, string packageName)
42+
{
43+
return await AddPackageDo.DoAsync(writerMethod, changeRunDir, packageName);
44+
}
45+
46+
public static async System.Threading.Tasks.Task<int> RemovePackageAsync(Action<string> writerMethod, string changeRunDir, string packageName)
47+
{
48+
return await RemovePackageDo.DoAsync(writerMethod, changeRunDir, packageName);
49+
}
50+
51+
public static string GetLockFilePath(string changeRunDir)
52+
{
53+
return PackageLocker.GetLockFilePath(changeRunDir);
54+
}
55+
56+
public static string GetManifestFilePath(string changeRunDir)
57+
{
58+
return IntentDescriptor.GetManifestFilePath(changeRunDir);
59+
}
4060
}
4161
}

agsget/agsget/EditorPlugin/AGS.Plugin.AgsGet/AgsGetCore/ManifestAndLock/IntentDescriptor.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@ class IntentDescriptor
1919
{
2020
private const string ManifestFile = "agsget-manifest.json";
2121

22-
private static string GetManifestFilePath()
22+
public static string GetManifestFilePath(string changeRunDir)
2323
{
24+
BaseFiles.SetRunDirectory(changeRunDir);
2425
return Path.Combine(BaseFiles.GetRunDirectory(), ManifestFile);
2526
}
2627

28+
public static string GetManifestFilePath()
29+
{
30+
return Path.Combine(BaseFiles.GetRunDirectory(), ManifestFile);
31+
}
2732
public static bool ManifestExists()
2833
{
2934
return File.Exists(GetManifestFilePath());

0 commit comments

Comments
 (0)