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

Registry dicts #18

Merged
merged 2 commits into from
Sep 24, 2014
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions CKAN/CKAN/InstalledModule.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
using System;
using System.Collections.Generic;

namespace CKAN
{
public class InstalledModuleFile
{
public string name;
public string sha1_sum;
}

public class InstalledModule
{
public InstalledModuleFile[] installed_files;
public Dictionary<string, InstalledModuleFile> installed_files;
public Module source_module;
public DateTime install_time;

public InstalledModule (InstalledModuleFile[] installed_files, Module source_module, DateTime install_time)
public InstalledModule (Dictionary <string, InstalledModuleFile> installed_files, Module source_module, DateTime install_time)
{
this.installed_files = installed_files;
this.source_module = source_module;
Expand Down
11 changes: 5 additions & 6 deletions CKAN/CKAN/ModuleInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public string download (Module module, string filename = null)

public void install (Module module, string filename = null)
{
List<InstalledModuleFile> module_files = new List<InstalledModuleFile> ();
Dictionary<string, InstalledModuleFile> module_files = new Dictionary<string, InstalledModuleFile> ();

Console.WriteLine (module.identifier + ":\n");

Expand Down Expand Up @@ -89,8 +89,8 @@ public void install (Module module, string filename = null)
}

Registry registry = registry_manager.load_or_create ();
registry_manager.save(
registry.append (new InstalledModule (module_files.ToArray(), module, DateTime.Now)));
registry.register_module (new InstalledModule (module_files, module, DateTime.Now));
registry_manager.save (registry);

return;

Expand All @@ -108,7 +108,7 @@ string sha1_sum (string path)
};
}

void install_component (dynamic stanza, ZipFile zipfile, List<InstalledModuleFile> module_files)
void install_component (dynamic stanza, ZipFile zipfile, Dictionary<string, InstalledModuleFile> module_files)
{
string fileToInstall = stanza.file;

Expand Down Expand Up @@ -150,9 +150,8 @@ void install_component (dynamic stanza, ZipFile zipfile, List<InstalledModuleFil

copyZipEntry (zipfile, entry, fullPath);

module_files.Add (new InstalledModuleFile {
module_files.Add (outputName, new InstalledModuleFile {
sha1_sum = sha1_sum (fullPath),
name = outputName,
});
}

Expand Down
14 changes: 5 additions & 9 deletions CKAN/CKAN/Registry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public class Registry
{
const int LATEST_REGISTRY_VERSION = 0;
public int registry_version;
public InstalledModule[] installed_modules;
public Dictionary<string, InstalledModule> installed_modules;

public Registry (int version, InstalledModule[] mods)
public Registry (int version, Dictionary<string, InstalledModule> mods)
{
/* TODO: support more than just the latest version */
if (version != LATEST_REGISTRY_VERSION) {
Expand All @@ -31,16 +31,12 @@ public Registry (int version, InstalledModule[] mods)

public static Registry empty ()
{
return new Registry (LATEST_REGISTRY_VERSION, new InstalledModule[] {});
return new Registry (LATEST_REGISTRY_VERSION, new Dictionary<string, InstalledModule> ());
}

public Registry append (InstalledModule mod)
public void register_module (InstalledModule mod)
{
/* UGH! I wish we could easily use 4.5's immutable collections */
InstalledModule[] new_modules = new InstalledModule[installed_modules.Length + 1];
installed_modules.CopyTo (new_modules, 0);
new_modules.SetValue (mod, installed_modules.Length);
return new Registry (registry_version, new_modules);
installed_modules.Add (mod.source_module.identifier, mod);
}
}
}