-
Notifications
You must be signed in to change notification settings - Fork 0
/
InterfaceManager.cs
165 lines (141 loc) · 4.17 KB
/
InterfaceManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
using System;
using System.Linq;
namespace OSRSCache
{
using InterfaceDefinition = OSRSCache.definitions.InterfaceDefinition;
using InterfaceExporter = OSRSCache.definitions.exporters.InterfaceExporter;
using InterfaceLoader = OSRSCache.definitions.loaders.InterfaceLoader;
using Archive = OSRSCache.fs.Archive;
using ArchiveFiles = OSRSCache.fs.ArchiveFiles;
using FSFile = OSRSCache.fs.FSFile;
using Index = OSRSCache.fs.Index;
using Storage = OSRSCache.fs.Storage;
using Store = OSRSCache.fs.Store;
using Namer = OSRSCache.util.Namer;
public class InterfaceManager
{
private readonly Store store;
private InterfaceDefinition[][] interfaces;
private readonly Namer namer = new Namer();
public InterfaceManager(Store store)
{
this.store = store;
}
public virtual void load()
{
InterfaceLoader loader = new InterfaceLoader();
Storage storage = store.Storage;
Index index = store.getIndex(IndexType.INTERFACES);
int max = index.Archives.Select(a => a.ArchiveId).Max();
interfaces = new InterfaceDefinition[max + 1][];
foreach (Archive archive in index.Archives)
{
int archiveId = archive.ArchiveId;
byte[] archiveData = storage.loadArchive(archive);
ArchiveFiles files = archive.getFiles(archiveData);
InterfaceDefinition[] ifaces = interfaces[archiveId];
if (ifaces == null)
{
ifaces = interfaces[archiveId] = new InterfaceDefinition[archive.FileData.Length];
}
foreach (FSFile file in files.Files)
{
int fileId = file.FileId;
int widgetId = (archiveId << 16) + fileId;
InterfaceDefinition iface = loader.load(widgetId, file.Contents);
ifaces[fileId] = iface;
}
}
}
public virtual int NumInterfaceGroups
{
get
{
return interfaces.Length;
}
}
public virtual int getNumChildren(int groupId)
{
return interfaces[groupId].Length;
}
public virtual InterfaceDefinition[] getIntefaceGroup(int groupId)
{
return interfaces[groupId];
}
public virtual InterfaceDefinition getInterface(int groupId, int childId)
{
return interfaces[groupId][childId];
}
public virtual InterfaceDefinition[][] Interfaces
{
get
{
return interfaces;
}
}
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void export(java.io.File out) throws java.io.IOException
public virtual void export(string @out)
{
// @out.mkdirs(); // TODO: ???
foreach (InterfaceDefinition[] defs in interfaces)
{
if (defs == null)
{
continue;
}
foreach (InterfaceDefinition def in defs)
{
if (def == null)
{
continue;
}
InterfaceExporter exporter = new InterfaceExporter(def);
string folder = $"{@out}/{(int)((uint)def.id >> 16)}";
// folder.mkdirs();
string targ = $"{folder}/{def.id & 0xffff}.json";
exporter.exportTo(targ);
}
}
}
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void java(java.io.File java) throws java.io.IOException
public virtual void java(string java)
{
Console.WriteLine($"InterfaceManager.java not implemented! {java}");
// System.setProperty("line.separator", "\n");
// java.mkdirs();
// File targ = new File(java, "InterfaceID.java");
// using (PrintWriter fw = new PrintWriter(targ))
// {
// fw.println("/* This file is automatically generated. Do not edit. */");
// fw.println("package net.runelite.api;");
// fw.println("");
// fw.println("public final class InterfaceID {");
// foreach (InterfaceDefinition[] defs in interfaces)
// {
// if (defs == null)
// {
// continue;
// }
// foreach (InterfaceDefinition def in defs)
// {
// if (def == null || string.ReferenceEquals(def.name, null) || def.name.Equals("NULL", StringComparison.OrdinalIgnoreCase))
// {
// continue;
// }
//
// string name = namer.name(def.name, def.id);
// if (string.ReferenceEquals(name, null))
// {
// continue;
// }
//
// fw.println(" public static final int " + name + " = " + def.id + ";");
// }
// }
// fw.println("}");
// }
}
}
}