-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
315 additions
and
182 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
10 changes: 10 additions & 0 deletions
10
WoWDatabaseEditor.Common/WDE.DbcStore/Providers/DBCProvider.cs
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,10 @@ | ||
using DBCD.Providers; | ||
using System.IO; | ||
|
||
namespace WDE.DbcStore.Providers | ||
{ | ||
public class DBCProvider : IDBCProvider | ||
{ | ||
public Stream StreamForTableName(string tableName, string build) => File.OpenRead(tableName); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
WoWDatabaseEditor.Common/WDE.DbcStore/Providers/DBDProvider.cs
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,47 @@ | ||
using DBCD.Providers; | ||
using System; | ||
using System.IO; | ||
using System.Net.Http; | ||
|
||
namespace WDE.DbcStore.Providers | ||
{ | ||
public class DBDProvider : IDBDProvider | ||
{ | ||
private static Uri BaseURI = new Uri("https://raw.githubusercontent.com/wowdev/WoWDBDefs/master/definitions/"); | ||
private static string CachePath = "dbdCache/"; | ||
private HttpClient client = new HttpClient(); | ||
|
||
public DBDProvider() | ||
{ | ||
if (!Directory.Exists(CachePath)) | ||
Directory.CreateDirectory(CachePath); | ||
|
||
client.BaseAddress = BaseURI; | ||
} | ||
|
||
public Stream StreamForTableName(string tableName, string build = null) | ||
{ | ||
string dbdName = Path.GetFileName(tableName).Replace(".db2", ".dbd"); | ||
|
||
if (!File.Exists($"{CachePath}/{dbdName}") || (DateTime.Now - File.GetLastWriteTime($"{CachePath}/{dbdName}")).TotalHours > 24) | ||
{ | ||
try | ||
{ | ||
var bytes = client.GetByteArrayAsync(dbdName).Result; | ||
File.WriteAllBytes($"{CachePath}/{dbdName}", bytes); | ||
|
||
return new MemoryStream(bytes); | ||
} | ||
catch (HttpRequestException /*requestException*/) | ||
{ | ||
if (File.Exists($"{CachePath}/{dbdName}")) | ||
return new MemoryStream(File.ReadAllBytes($"{CachePath}/{dbdName}")); | ||
else | ||
return null; | ||
} | ||
} | ||
else | ||
return new MemoryStream(File.ReadAllBytes($"{CachePath}/{dbdName}")); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.