|
|
@ -12,21 +12,23 @@ namespace EGFramework |
|
|
|
{ |
|
|
|
{ |
|
|
|
public Encoding StringEncoding { set; get; } = Encoding.UTF8; |
|
|
|
public Encoding StringEncoding { set; get; } = Encoding.UTF8; |
|
|
|
private string DefaultPath { set; get; } |
|
|
|
private string DefaultPath { set; get; } |
|
|
|
private IEnumerable<string[]> CsvDataBlock { get; set; } |
|
|
|
private List<string[]> CsvDataBlock { get; set; } |
|
|
|
private string[] CsvDataHeader; |
|
|
|
private string[] CsvDataHeader; |
|
|
|
private string ReadText { set; get; } |
|
|
|
private string ReadText { set; get; } |
|
|
|
public void InitSaveFile(string path) |
|
|
|
public void InitSaveFile(string path) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
ReadDataBlock(path); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void ReadDataBlock(string path){ |
|
|
|
public void ReadDataBlock(string path){ |
|
|
|
|
|
|
|
DefaultPath = path; |
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
FileStream fileStream = new FileStream(path,FileMode.Open); |
|
|
|
FileStream fileStream = new FileStream(path,FileMode.Open); |
|
|
|
byte[] buffer = new byte[fileStream.Length]; |
|
|
|
byte[] buffer = new byte[fileStream.Length]; |
|
|
|
fileStream.Read(buffer, 0, (int)fileStream.Length); |
|
|
|
fileStream.Read(buffer, 0, (int)fileStream.Length); |
|
|
|
fileStream.Close(); |
|
|
|
fileStream.Close(); |
|
|
|
|
|
|
|
fileStream.Dispose(); |
|
|
|
ReadText = StringEncoding.GetString(buffer); |
|
|
|
ReadText = StringEncoding.GetString(buffer); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (System.Exception e) |
|
|
|
catch (System.Exception e) |
|
|
@ -38,7 +40,41 @@ namespace EGFramework |
|
|
|
CsvDataBlock = GetCSVDataBlockFromText(ReadText,out CsvDataHeader); |
|
|
|
CsvDataBlock = GetCSVDataBlockFromText(ReadText,out CsvDataHeader); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
public IEnumerable<string[]> GetCSVDataBlockFromText(string text,out string[] header){ |
|
|
|
|
|
|
|
|
|
|
|
public void WriteDataBlock(string path){ |
|
|
|
|
|
|
|
try |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
FileStream fileStream = File.Create(path); |
|
|
|
|
|
|
|
string writeText = ""; |
|
|
|
|
|
|
|
string headerText = ""; |
|
|
|
|
|
|
|
foreach(string headers in CsvDataHeader){ |
|
|
|
|
|
|
|
headerText+=headers + ","; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
headerText = headerText.Remove(headerText.Length-1,1); |
|
|
|
|
|
|
|
writeText = headerText + "\n"; |
|
|
|
|
|
|
|
foreach(string[] lineData in CsvDataBlock){ |
|
|
|
|
|
|
|
string lineText = ""; |
|
|
|
|
|
|
|
foreach(string singleData in lineData){ |
|
|
|
|
|
|
|
lineText += singleData + ","; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
lineText = lineText.Remove(lineText.Length-1,1); |
|
|
|
|
|
|
|
writeText += lineText + "\n"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
writeText = writeText.Remove(writeText.Length-1,1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
byte[] data = StringEncoding.GetBytes(writeText); |
|
|
|
|
|
|
|
fileStream.Write(data,0,data.Length); |
|
|
|
|
|
|
|
fileStream.Close(); |
|
|
|
|
|
|
|
fileStream.Dispose(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (System.Exception e) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Godot.GD.Print("e:" + e); |
|
|
|
|
|
|
|
throw; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<string[]> GetCSVDataBlockFromText(string text,out string[] header){ |
|
|
|
List<string[]> csvBlock = new List<string[]>(); |
|
|
|
List<string[]> csvBlock = new List<string[]>(); |
|
|
|
string[] lineData = text.Split('\n'); |
|
|
|
string[] lineData = text.Split('\n'); |
|
|
|
header = lineData[0].Split(','); |
|
|
|
header = lineData[0].Split(','); |
|
|
@ -51,6 +87,19 @@ namespace EGFramework |
|
|
|
return csvBlock; |
|
|
|
return csvBlock; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public string[] ReadLine(int id){ |
|
|
|
|
|
|
|
if(CsvDataBlock.Count()>0){ |
|
|
|
|
|
|
|
return CsvDataBlock[id]; |
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void WriteLine(string[] lineData){ |
|
|
|
|
|
|
|
CsvDataBlock.Add(lineData); |
|
|
|
|
|
|
|
this.WriteDataBlock(DefaultPath); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void SetData<TData>(string dataKey, TData data, object id) |
|
|
|
public void SetData<TData>(string dataKey, TData data, object id) |
|
|
|
{ |
|
|
|
{ |
|
|
|
throw new NotImplementedException(); |
|
|
|
throw new NotImplementedException(); |
|
|
@ -63,7 +112,7 @@ namespace EGFramework |
|
|
|
{ |
|
|
|
{ |
|
|
|
throw new NotImplementedException(); |
|
|
|
throw new NotImplementedException(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public IEnumerable<TData> FindData<TData>(string dataKey, Expression<Func<TData, bool>> expression) where TData : new() |
|
|
|
public IEnumerable<TData> FindData<TData>(string dataKey, Expression<Func<TData, bool>> expression) where TData : new() |
|
|
|
{ |
|
|
|
{ |
|
|
|
throw new NotImplementedException(); |
|
|
|
throw new NotImplementedException(); |
|
|
|