Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static class Ulitityclass
- {
- public static int ReadFromFile(ref playersignup[] players)
- {
- int size = 0;
- Stream sr;
- try
- {
- sr = File.OpenRead("PlayerDetails.bin");
- BinaryFormatter bf = new BinaryFormatter();
- try
- {
- while (sr.Position < sr.Length)
- {
- players[size] = (playersignup)bf.Deserialize(sr);
- size++;
- }
- sr.Close();
- }
- catch (SerializationException e)
- {
- sr.Close();
- return size;
- }
- return size;
- }
- catch (IOException e)
- {
- }
- return size;
- }
- public static void DisplayUsers()
- {
- Stream sr;
- playersignup player;
- try
- {
- sr = File.OpenRead("players.txt");
- BinaryFormatter bf = new BinaryFormatter();
- try
- {
- while (sr.Position < sr.Length)
- {
- player = (playersignup)bf.Deserialize(sr);
- //
- }
- }
- catch (SerializationException e)
- {
- }
- sr.Close();
- sr.Dispose();
- }
- catch (IOException e)
- {
- //
- }
- }
- public static void DisplayusersBinary()
- {
- playersignup player;
- Stream sr;
- try
- {
- sr = File.OpenRead("PlayerDetails.bin");
- BinaryFormatter bf = new BinaryFormatter();
- try
- {
- while (sr.Position < sr.Length)
- {
- player = (playersignup)bf.Deserialize(sr);
- }
- }
- catch (SerializationException e)
- {
- }
- sr.Close();
- sr.Dispose();
- }
- catch (IOException e)
- {
- }
- }
- public static void WriteToFile(playersignup[] players, int size)
- {
- Stream sw;
- BinaryFormatter bf = new BinaryFormatter();
- try
- {
- sw = File.Open("PlayerDetails.bin", FileMode.Create);
- bf.Serialize(sw, players[0]);
- sw.Close();
- //open as append and write rest of array
- sw = File.Open("PlayerDetails.bin", FileMode.Append);
- //serialialize new player
- for (int x = 1; x < size; x++)
- {
- bf.Serialize(sw, players[x]);
- }
- sw.Close();
- }
- catch (IOException e)
- {
- //(e.Message);
- }
- }
- public static bool UserExists(playersignup[] players, string userna,string passwo,string ema)
- {
- foreach (playersignup player in players)
- {
- //if user is registered, the method returns true
- if (player != null)
- {
- if ((player.Username == userna)&&(player.Password==passwo)&&(player.Email==ema))
- {
- return true;
- }
- }
- }
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement