-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dev
- Loading branch information
Showing
18 changed files
with
300 additions
and
780 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.IO.Compression; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace DeepDungeonDex; | ||
|
||
public partial class Requests | ||
{ | ||
private ZipArchive? _fileStream; | ||
|
||
public async Task<string?> GetFromFile(string path) | ||
{ | ||
if (_fileStream == null) | ||
GetDat("DeepDungeonDex.data.dat"); | ||
|
||
try | ||
{ | ||
path = path.Replace("/", "\\"); | ||
var entry = _fileStream!.Entries.FirstOrDefault(e => e.FullName == path); | ||
if (entry == null) | ||
return null; | ||
await using var stream = entry.Open(); | ||
using var reader = new StreamReader(stream); | ||
return await reader.ReadToEndAsync(); | ||
} | ||
catch (Exception e) | ||
{ | ||
_log.Error(e, $"Error while trying to read: {path}"); | ||
return null; | ||
} | ||
} | ||
|
||
public async Task<Dictionary<string, string[]>?> GetFileListFromFile() | ||
{ | ||
var content = await GetFromFile("index.json"); | ||
return content == null ? null : JsonConvert.DeserializeObject<Dictionary<string, string[]>>(content); | ||
} | ||
|
||
public void GetDat(string path) | ||
{ | ||
var compStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(path)!; | ||
var stream = new ZipArchive(compStream, ZipArchiveMode.Read); | ||
_fileStream = stream; | ||
} | ||
} |
Oops, something went wrong.