public static void IndexNamedData(string dataPath) { try { EntryDataIndex fullGuide = new EntryDataIndex(); foreach (string dir in Directory.GetFiles(dataPath, "*" + DataManager.DATA_EXT)) { string file = Path.GetFileNameWithoutExtension(dir); int num = Convert.ToInt32(file); IEntryData data = (IEntryData)DataManager.LoadData(dir); while (fullGuide.Entries.Count <= num) { fullGuide.Entries.Add(new EntrySummary()); } fullGuide.Entries[num] = data.GenerateEntrySummary(); } using (Stream stream = new FileStream(dataPath + "index.idx", FileMode.Create, FileAccess.Write, FileShare.None)) { using (BinaryWriter writer = new BinaryWriter(stream)) { IFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, fullGuide); } } } catch (Exception ex) { DiagManager.Instance.LogError(new Exception("Error importing index at " + dataPath + "\n", ex)); } }
public static void ReserializeData(string dataPath, string ext) { foreach (string dir in PathMod.GetModFiles(dataPath, "*" + ext)) { IEntryData data = (IEntryData)DataManager.LoadData(dir, DiagManager.Instance.UpgradeBinder); DataManager.SaveData(dir, data); } }
public static void ReserializeData(string dataPath, string ext, SerializationBinder binder) { foreach (string dir in Directory.GetFiles(dataPath, "*" + ext)) { IEntryData data = (IEntryData)DataManager.LoadData(dir, binder); DataManager.SaveData(dir, data); } }
public static void Register(EntryType type, IEntryData handler) { if (IsRegistered(type)) { Console.WriteLine("WARN: Handler for " + type.ToString() + " already registered!"); return; } _handlers.Add(type, handler); }
public static void DemoData(string dataPath, string ext) { foreach (string dir in PathMod.GetModFiles(dataPath, "*" + ext)) { IEntryData data = (IEntryData)DataManager.LoadData(dir); if (!data.Released) { data = (IEntryData)ReflectionExt.CreateMinimalInstance(data.GetType()); } DataManager.SaveData(dir, data); } }
public static void IndexHardcodedNamedData(string dataPath, GetNamedData getData, int max) { try { EntryDataIndex fullGuide = new EntryDataIndex(); fullGuide.Entries = new EntrySummary[max]; for (int ii = 0; ii < max; ii++) { IEntryData data = getData(ii); fullGuide.Entries[ii] = data.GenerateEntrySummary(); } DataManager.SaveData(dataPath + "index.idx", fullGuide); } catch (Exception ex) { DiagManager.Instance.LogError(new Exception("Error importing index at " + dataPath + "\n", ex)); } }
private void OpenList(DataManager.DataType dataType, GetEntry entryOp, CreateEntry createOp) { DataList choices = new DataList(); choices.Text = dataType.ToString(); string[] entries = DataManager.Instance.DataIndices[dataType].GetLocalStringArray(true); choices.AddEntries(entries); choices.SelectedOKEvent = () => { if (choices.ChosenEntry > -1) { ElementForm editor = new ElementForm(); int entryNum = choices.ChosenEntry; editor.Text = entries[entryNum]; IEntryData data = entryOp(entryNum); editor.Text = data.ToString();//data.GetType().ToString() + "#" + entryNum; DataEditor.LoadDataControls(data, editor.ControlPanel); editor.OnOK += (object okSender, EventArgs okE) => { object obj = data; DataEditor.SaveDataControls(ref obj, editor.ControlPanel); data = (IEntryData)obj; DataManager.SaveData(entryNum, dataType.ToString(), data); DataManager.Instance.ClearCache(dataType); IEntryData entryData = ((IEntryData)data); EntrySummary entrySummary = entryData.GenerateEntrySummary(); DataManager.Instance.DataIndices[dataType].Entries[entryNum] = entrySummary; DataManager.Instance.SaveIndex(dataType); choices.ModifyEntry(entryNum, entrySummary.GetLocalString(true)); editor.Close(); }; editor.OnCancel += (object okSender, EventArgs okE) => { editor.Close(); }; editor.Show(); } }; choices.SelectedAddEvent = () => { ElementForm editor = new ElementForm(); int entryNum = DataManager.Instance.DataIndices[dataType].Entries.Count; editor.Text = "New " + dataType.ToString(); IEntryData data = createOp(); editor.Text = data.ToString();//data.GetType().ToString() + "#" + entryNum; DataEditor.LoadDataControls(data, editor.ControlPanel); editor.OnOK += (object okSender, EventArgs okE) => { object obj = data; DataEditor.SaveDataControls(ref obj, editor.ControlPanel); data = (IEntryData)obj; DataManager.SaveData(entryNum, dataType.ToString(), data); DataManager.Instance.ClearCache(dataType); IEntryData entryData = ((IEntryData)data); EntrySummary entrySummary = entryData.GenerateEntrySummary(); DataManager.Instance.DataIndices[dataType].Entries.Add(entrySummary); DataManager.Instance.SaveIndex(dataType); entries = DataManager.Instance.DataIndices[dataType].GetLocalStringArray(true); choices.AddEntry(entrySummary.GetLocalString(true)); editor.Close(); }; editor.OnCancel += (object okSender, EventArgs okE) => { editor.Close(); }; editor.Show(); }; choices.Show(); }
public void SetValue(IEntryData instance , object data) { var obj = instance as GenericPackageData; obj.SetValue(m_index,data); }
public object GetValue(IEntryData instance) { var obj = instance as GenericPackageData; return obj.GetValue(m_index); }
private void OpenList(DataManager.DataType dataType, GetEntry entryOp, CreateEntry createOp) { lock (GameBase.lockObj) { DataListFormViewModel choices = new DataListFormViewModel(); choices.Name = dataType.ToString(); string[] entries = DataManager.Instance.DataIndices[dataType].GetLocalStringArray(true); choices.SetEntries(entries); choices.SelectedOKEvent += () => { if (choices.SearchList.InternalIndex > -1) { lock (GameBase.lockObj) { int entryNum = choices.SearchList.InternalIndex; IEntryData data = entryOp(entryNum); Views.DataEditForm editor = new Views.DataEditForm(); editor.Title = DataEditor.GetWindowTitle(String.Format("{0} #{1:D3}", dataType.ToString(), entryNum), data.Name.ToLocal(), data, data.GetType()); DataEditor.LoadDataControls(data, editor.ControlPanel); editor.SelectedOKEvent += () => { lock (GameBase.lockObj) { object obj = data; DataEditor.SaveDataControls(ref obj, editor.ControlPanel); DataManager.Instance.ContentChanged(dataType, entryNum, (IEntryData)obj); string newName = DataManager.Instance.DataIndices[dataType].Entries[entryNum].GetLocalString(true); choices.ModifyEntry(entryNum, newName); editor.Close(); } }; editor.SelectedCancelEvent += () => { editor.Close(); }; editor.Show(); } } }; choices.SelectedAddEvent += () => { lock (GameBase.lockObj) { int entryNum = DataManager.Instance.DataIndices[dataType].Entries.Count; IEntryData data = createOp(); Views.DataEditForm editor = new Views.DataEditForm(); editor.Title = DataEditor.GetWindowTitle(String.Format("{0} #{1:D3}", dataType.ToString(), entryNum), data.Name.ToLocal(), data, data.GetType()); data.ToString(); DataEditor.LoadDataControls(data, editor.ControlPanel); editor.SelectedOKEvent += () => { lock (GameBase.lockObj) { object obj = data; DataEditor.SaveDataControls(ref obj, editor.ControlPanel); data = (IEntryData)obj; DataManager.Instance.ContentChanged(dataType, entryNum, (IEntryData)obj); string newName = DataManager.Instance.DataIndices[dataType].Entries[entryNum].GetLocalString(true); choices.AddEntry(newName); editor.Close(); } }; editor.SelectedCancelEvent += () => { editor.Close(); }; editor.Show(); } }; choices.SelectedReindexEvent += () => { lock (GameBase.lockObj) { DevHelper.RunIndexing(dataType); DevHelper.RunExtraIndexing(dataType); DataManager.Instance.LoadIndex(dataType); DataManager.Instance.LoadUniversalData(); DataManager.Instance.ClearCache(dataType); DiagManager.Instance.DevEditor.ReloadData(dataType); string[] entries = DataManager.Instance.DataIndices[dataType].GetLocalStringArray(true); choices.SetEntries(entries); } }; Views.DataListForm dataListForm = new Views.DataListForm { DataContext = choices, }; dataListForm.Show(); } }
public void Consume(IEntryData entryData) { if (entryData.GetEntryType().FullName == "Whitelog.Interface.LogEntry") { var titleInfo = (entryData.GetProperties().ElementAt(2).GetValue(entryData) as GenericPackageData); int scopeId = (int) (entryData.GetProperties().ElementAt(1).GetValue(entryData)); if (titleInfo.Type == "Whitelog.Core.OpenLogScopeTitle") { int parentScopeId = (int) titleInfo.GetValue(1); var node= new LogNode() { Time = (DateTime) entryData.GetProperties().ElementAt(0).GetValue(entryData), Title = null, Message = titleInfo.GetValue(0).ToString(), Children = new List<LogNode>(), }; m_openNodes.Add(scopeId,node); LogNode parentNode; if (m_openNodes.TryGetValue(parentScopeId, out parentNode)) { parentNode.Children.Add(node); RaiseEvent(parentNode,false); } else { LogNodes.Add(node); RaiseEvent(node,true); } } else if (titleInfo.Type == "Whitelog.Core.CloseLogScopeTitle") { if (m_openNodes.ContainsKey(scopeId)) { LogNode parentNode; if (m_openNodes.TryGetValue(scopeId, out parentNode)) { parentNode.Children.Add(new LogNode() { Message = "<-", Time = (DateTime)entryData.GetProperties().ElementAt(0).GetValue(entryData), Title = null, }); RaiseEvent(parentNode, false); } m_openNodes.Remove(scopeId); } } else { var node = new LogNode() { Time = (DateTime) entryData.GetProperties().ElementAt(0).GetValue(entryData), Title = titleInfo.GetValue(1).ToString(), Message = titleInfo.GetValue(0).ToString(), }; LogNode parentNode; if (m_openNodes.TryGetValue(scopeId, out parentNode)) { parentNode.Children.Add(node); RaiseEvent(parentNode,false); } else { LogNodes.Add(node); RaiseEvent(node,true); } } } }
public void EditEntry(int index, bool forceHex = false) { BundleEntry entry = GetEntry(index); if (EntryTypeRegistry.IsRegistered(entry.Type) && !forceHex) { IEntryData data = EntryTypeRegistry.GetHandler(entry.Type); TextureCache.ResetCache(); LoadingDialog loader = new LoadingDialog(); loader.Status = "Loading: " + entry.ID.ToString("X8"); Thread loadInstanceThread = null; bool failure = false; loader.Done += (cancelled, value) => { if (cancelled) { loadInstanceThread?.Abort(); } else { if (failure) { MessageBox.Show(this, "Failed to load Entry", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { loader.Hide(); IEntryEditor editor = data.GetEditor(entry); if (editor != null) { editor.ShowDialog(this); } else { DebugUtil.ShowDebug(this, data); } if (ForceOnlySpecificEntry) { Environment.Exit(0); } } } TextureCache.ResetCache(); }; loadInstanceThread = new Thread(() => { try { try { failure = !data.Read(entry, loader); } catch (ReadFailedError ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); failure = true; throw; } } catch (Exception) { MessageBox.Show("Failed to load Entry", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); failure = true; } loader.IsDone = true; }); loadInstanceThread.Start(); loader.ShowDialog(this); } else { EntryEditor editor = new EntryEditor(); editor.ForceHex = forceHex; Task.Run(() => openEditor(editor, index)); editor.ShowDialog(this); } }