bro i can't even keep track anymore
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
namespace Profiles
|
||||
using System.Collections;
|
||||
|
||||
namespace Profiles
|
||||
{
|
||||
abstract class IList<T>
|
||||
abstract class IList<T> : IEnumerable<T>
|
||||
{
|
||||
protected T[] list;
|
||||
|
||||
@@ -32,5 +34,15 @@
|
||||
{
|
||||
list = new T[0];
|
||||
}
|
||||
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
return ((IEnumerable<T>)list).GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return list.GetEnumerator();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,11 +7,23 @@ namespace Profiles
|
||||
{
|
||||
public static Profile CurrentProfile;
|
||||
public static ProfileList ListOfProfiles;
|
||||
private static string filePath = SpecialDirectories.CurrentUserApplicationData + "Profiles.csv";
|
||||
private static string filePath = SpecialDirectories.CurrentUserApplicationData + "\\Profiles.csv";
|
||||
|
||||
public static void AddProfile(string profileName, string profilePath)
|
||||
{
|
||||
ListOfProfiles.Add(new Profile(profileName, profilePath));
|
||||
ChangeProfiles(profileName);
|
||||
}
|
||||
|
||||
public static void ChangeProfiles(string profileName)
|
||||
{
|
||||
CurrentProfile = ListOfProfiles.SearchByName(profileName);
|
||||
try
|
||||
{
|
||||
CurrentProfile = ListOfProfiles.SearchByName(profileName);
|
||||
} catch (ProfileNotFoundException)
|
||||
{
|
||||
MessageBox.Show("The selected profile cannot be found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Init()
|
||||
@@ -20,14 +32,14 @@ namespace Profiles
|
||||
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
LoadProfiles();
|
||||
LoadProfilesFile();
|
||||
}
|
||||
else
|
||||
{
|
||||
CreateProfiles();
|
||||
CreateProfilesFile();
|
||||
}
|
||||
}
|
||||
private static void LoadProfiles()
|
||||
private static void LoadProfilesFile()
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -43,7 +55,7 @@ namespace Profiles
|
||||
{
|
||||
//File is messed up, creating new one
|
||||
sr.Close();
|
||||
CreateProfiles();
|
||||
CreateProfilesFile();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -56,11 +68,53 @@ namespace Profiles
|
||||
|
||||
private static void TrimLastLine()
|
||||
{
|
||||
List<string> lines = File.ReadAllLines(filePath).ToList();
|
||||
File.WriteAllLines(filePath, lines.GetRange(0, lines.Count - 1).ToArray());
|
||||
try
|
||||
{
|
||||
StreamReader sr = new StreamReader(filePath);
|
||||
List<string> validLines = new List<string>();
|
||||
|
||||
while (!sr.EndOfStream)
|
||||
{
|
||||
string? line = sr.ReadLine();
|
||||
if (line != null)
|
||||
{
|
||||
validLines.Add(line);
|
||||
}
|
||||
}
|
||||
|
||||
sr.Close();
|
||||
File.WriteAllLines(filePath, validLines);
|
||||
} catch (IOException e)
|
||||
{
|
||||
MessageBox.Show(e.ToString(), "IO Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
} catch (UnauthorizedAccessException e)
|
||||
{
|
||||
MessageBox.Show(e.ToString(), "Can't access profiles file", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private static void CreateProfiles()
|
||||
public static void SaveProfiles()
|
||||
{
|
||||
try
|
||||
{
|
||||
StreamWriter sw = new StreamWriter(filePath);
|
||||
|
||||
foreach (Profile p in ListOfProfiles)
|
||||
{
|
||||
sw.WriteLine($"{p.Name},{p.Path}");
|
||||
}
|
||||
|
||||
sw.Close();
|
||||
} catch (IOException e)
|
||||
{
|
||||
MessageBox.Show(e.ToString(), "IO Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
} catch (UnauthorizedAccessException e)
|
||||
{
|
||||
MessageBox.Show(e.ToString(), "Can't access profiles file", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private static void CreateProfilesFile()
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -69,10 +123,9 @@ namespace Profiles
|
||||
string[] parameters = new string[2];
|
||||
|
||||
NewProfileForm np = new NewProfileForm();
|
||||
Profile firstProfile = null;
|
||||
np.NewProfileRequest += (string profileName, string profilePath) =>
|
||||
{
|
||||
firstProfile = new Profile(profileName, profilePath);
|
||||
Profile firstProfile = new Profile(profileName, profilePath);
|
||||
ListOfProfiles.Add(firstProfile);
|
||||
ChangeProfiles(firstProfile.Name);
|
||||
sw.WriteLine($"{firstProfile.Name},{firstProfile.Path}");
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
|
||||
public override Profile SearchByName(string name)
|
||||
{
|
||||
Profile result = null;
|
||||
Profile? result = null;
|
||||
|
||||
for (int i = 0; i < this.Length; i++)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user