Added users, bugfixes
This commit is contained in:
@@ -8,15 +8,28 @@ namespace ErgometerLibrary
|
|||||||
public class FileHandler
|
public class FileHandler
|
||||||
{
|
{
|
||||||
public static string DataFolder { get; } = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "Ergometer");
|
public static string DataFolder { get; } = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "Ergometer");
|
||||||
|
public static string UsersFile { get; } = Path.Combine(DataFolder, "users.ergo");
|
||||||
|
|
||||||
public static void CheckDataFolder()
|
public static void CheckStorage()
|
||||||
{
|
{
|
||||||
if(! Directory.Exists(DataFolder))
|
if(! Directory.Exists(DataFolder))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(DataFolder);
|
Directory.CreateDirectory(DataFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(! File.Exists(UsersFile))
|
||||||
|
{
|
||||||
|
using (Stream stream = File.Open(UsersFile, FileMode.Create))
|
||||||
|
{
|
||||||
|
BinaryWriter writer = new BinaryWriter(stream);
|
||||||
|
writer.Write(0);
|
||||||
|
writer.Write("doctor");
|
||||||
|
writer.Write("password");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//SESSION
|
||||||
public static int GenerateSession()
|
public static int GenerateSession()
|
||||||
{
|
{
|
||||||
string[] existingSessions = Directory.GetDirectories(DataFolder);
|
string[] existingSessions = Directory.GetDirectories(DataFolder);
|
||||||
@@ -37,6 +50,10 @@ namespace ErgometerLibrary
|
|||||||
{
|
{
|
||||||
Directory.CreateDirectory(GetSessionFolder(session));
|
Directory.CreateDirectory(GetSessionFolder(session));
|
||||||
|
|
||||||
|
using (File.Create(Path.Combine(GetSessionFile(session)))) ;
|
||||||
|
using (File.Create(Path.Combine(GetSessionMetingen(session)))) ;
|
||||||
|
using (File.Create(Path.Combine(GetSessionChat(session)))) ;
|
||||||
|
|
||||||
File.WriteAllText(GetSessionFile(session), naam + "\n" + Helper.Now);
|
File.WriteAllText(GetSessionFile(session), naam + "\n" + Helper.Now);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,5 +92,40 @@ namespace ErgometerLibrary
|
|||||||
{
|
{
|
||||||
return Path.Combine(DataFolder, session.ToString(), "chat.log");
|
return Path.Combine(DataFolder, session.ToString(), "chat.log");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//USER MANAGEMENT
|
||||||
|
public static Dictionary<string, string> LoadUsers()
|
||||||
|
{
|
||||||
|
Dictionary<string, string> users = new Dictionary<string, string>();
|
||||||
|
|
||||||
|
using (Stream stream = File.Open(UsersFile, FileMode.Open))
|
||||||
|
{
|
||||||
|
BinaryReader reader = new BinaryReader(stream);
|
||||||
|
int count = reader.ReadInt32();
|
||||||
|
for (int n = 0; n < count; n++)
|
||||||
|
{
|
||||||
|
var key = reader.ReadString();
|
||||||
|
var value = reader.ReadString();
|
||||||
|
users.Add(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return users;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SaveUsers(Dictionary<string, string> users)
|
||||||
|
{
|
||||||
|
using(Stream stream = File.Open(UsersFile, FileMode.Open))
|
||||||
|
{
|
||||||
|
BinaryWriter writer = new BinaryWriter(stream);
|
||||||
|
writer.Write(users.Count);
|
||||||
|
foreach (var kvp in users)
|
||||||
|
{
|
||||||
|
writer.Write(kvp.Key);
|
||||||
|
writer.Write(kvp.Value);
|
||||||
|
}
|
||||||
|
writer.Flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.0.2.2")]
|
[assembly: AssemblyVersion("1.0.2.5")]
|
||||||
[assembly: AssemblyFileVersion("1.0.2.2")]
|
[assembly: AssemblyFileVersion("1.0.2.5")]
|
||||||
|
|||||||
Reference in New Issue
Block a user