Commit bbb765d1 authored by mercury233's avatar mercury233

update Program.ReadFile

parent 3e8635b7
...@@ -59,7 +59,7 @@ namespace WindBot.Game.AI ...@@ -59,7 +59,7 @@ namespace WindBot.Game.AI
_game = game; _game = game;
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(DialogsData)); DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(DialogsData));
string dialogfilename = game.Dialog; string dialogfilename = game.Dialog;
using (FileStream fs = File.OpenRead("Dialogs/" + dialogfilename + ".json")) using (FileStream fs = Program.ReadFile("Dialogs", dialogfilename, "json"))
{ {
DialogsData data = (DialogsData)serializer.ReadObject(fs); DialogsData data = (DialogsData)serializer.ReadObject(fs);
_welcome = data.welcome; _welcome = data.welcome;
......
...@@ -43,7 +43,7 @@ namespace WindBot.Game ...@@ -43,7 +43,7 @@ namespace WindBot.Game
StreamReader reader = null; StreamReader reader = null;
try try
{ {
reader = new StreamReader(new FileStream("Decks/" + name + ".ydk", FileMode.Open, FileAccess.Read)); reader = new StreamReader(Program.ReadFile("Decks", name, "ydk"));
Deck deck = new Deck(); Deck deck = new Deck();
bool side = false; bool side = false;
......
...@@ -197,5 +197,22 @@ namespace WindBot ...@@ -197,5 +197,22 @@ namespace WindBot
} }
#endif #endif
} }
public static FileStream ReadFile(string directory, string filename, string extension)
{
string tryfilename = filename + "." + extension;
string fullpath = Path.Combine(directory, tryfilename);
if (!File.Exists(fullpath))
fullpath = filename;
if (!File.Exists(fullpath))
fullpath = Path.Combine("../", filename);
if (!File.Exists(fullpath))
fullpath = Path.Combine("../deck/", filename);
if (!File.Exists(fullpath))
fullpath = Path.Combine("../", tryfilename);
if (!File.Exists(fullpath))
fullpath = Path.Combine("../deck/", tryfilename);
return new FileStream(fullpath, FileMode.Open, FileAccess.Read);
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment