Skip to content

Commit

Permalink
OUT OF MEMORY
Browse files Browse the repository at this point in the history
  • Loading branch information
shoushou1106 committed Mar 3, 2024
1 parent 928c5f2 commit 42c5a7d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 16 deletions.
42 changes: 38 additions & 4 deletions IndexLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
using Newtonsoft.Json;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.IO;
using Newtonsoft.Json.Linq;

namespace FindinFilesPlugin
{
Expand Down Expand Up @@ -184,18 +186,50 @@ public static void InitializeIndex(CancellationToken cancelToken, ILogger inLogg
isIndexInitialized = true;
}

public static string IndexToJson()
public static void IndexToJson(string fileName)
{
if (isIndexInitialized == false)
throw new ArgumentNullException();

return JsonConvert.SerializeObject(ebxAssetIndex, Formatting.Indented);
//return JsonConvert.SerializeObject(ebxAssetIndex, Formatting.Indented);

using (StreamWriter writer = new StreamWriter(fileName))
using (JsonTextWriter jsonWriter = new JsonTextWriter(writer))
{
JsonSerializer jsonSerializer = new JsonSerializer();

jsonWriter.Formatting = Formatting.Indented;
jsonSerializer.Formatting = Formatting.Indented;

jsonSerializer.Serialize(jsonWriter, ebxAssetIndex);

jsonWriter.Flush();
jsonWriter.Close();
}
}

public static void JsonToIndex(string json)
public static void JsonToIndex(string fileName)
{
ebxAssetIndex.Clear();
ebxAssetIndex = JsonConvert.DeserializeObject<Dictionary<Guid, string>>(json);

//ebxAssetIndex = JsonConvert.DeserializeObject<Dictionary<Guid, string>>(json);

using (StreamReader reader = new StreamReader(fileName))
using (JsonTextReader jsonReader = new JsonTextReader(reader))
{
JsonSerializer jsonSerializer = new JsonSerializer();

ebxAssetIndex = jsonSerializer.Deserialize<Dictionary<Guid, string>>(jsonReader);

jsonReader.Close();
}

if (ebxAssetIndex is null)
{
ebxAssetIndex = new Dictionary<Guid, string>();
isIndexInitialized = false;
return;
}

isIndexInitialized = true;
}
Expand Down
16 changes: 4 additions & 12 deletions Windows/FindinFilesWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,9 @@ private void SaveIndexButton_Click(object sender, RoutedEventArgs e)

if (dialog.ShowDialog())
{
task.Update("Writing json file", 50.0);
using (StreamWriter writer = new StreamWriter(dialog.FileName))
{
writer.Write(IndexLibrary.IndexToJson());
}
task.Update("Writing json file");
IndexLibrary.IndexToJson(dialog.FileName);
}
task.Update("Complete", 100.0);
});

GC.Collect();
Expand All @@ -224,13 +220,9 @@ private void LoadIndexButton_Click(object sender, RoutedEventArgs e)

if (dialog.ShowDialog())
{
task.Update("Reading json file", 50.0);
using (StreamReader reader = new StreamReader(dialog.FileName))
{
reader.ReadToEnd();
}
task.Update("Reading json file");
IndexLibrary.JsonToIndex(dialog.FileName);
}
task.Update("Complete", 100.0);
});

UpdateUI();
Expand Down

0 comments on commit 42c5a7d

Please sign in to comment.