1
0
mirror of https://github.com/RaidMax/IW4M-Admin.git synced 2025-06-12 08:08:06 -05:00

Cleaned up some code and adhered closer to the Microsoft code standards.

This commit is contained in:
RaidMax
2017-06-12 13:50:00 -04:00
parent 7a81f6c2bd
commit 0ef306a60c
22 changed files with 507 additions and 573 deletions

View File

@ -10,86 +10,30 @@ namespace SharedLibrary
{
public IFile(String fileName)
{
//Not safe for directories with more than one folder but meh
string[] asd = fileName.Split('/');
if (asd[0] != "")
_Directory = asd[0];
else
_Directory = asd[2];
Name = (fileName.Split('/'))[fileName.Split('/').Length - 1];
try
{
Handle = new StreamReader(new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
sze = Handle.BaseStream.Length;
}
catch
{
//Console.WriteLine("Unable to open log file for writing!");
}
}
public IFile(String file, bool write)
{
Name = file;
writeHandle = new StreamWriter(new FileStream(Name, FileMode.Create, FileAccess.Write, FileShare.ReadWrite));
sze = 0;
}
public IFile()
{
WebClient request = new WebClient();
string url = $"http://raidmax.org/logs/IW4X/games_mp.log";
byte[] newFileData = request.DownloadData(url);
Handle = new StreamReader(new MemoryStream(newFileData));
Name = fileName;
Handle = new StreamReader(new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
sze = Handle.BaseStream.Length;
}
public long getSize()
public long Length()
{
sze = Handle.BaseStream.Length;
return sze;
}
public void Write(String line)
{
if (writeHandle != null)
{
try
{
writeHandle.WriteLine(line);
writeHandle.Flush();
}
catch (Exception E)
{
Console.WriteLine("Error during flush", E.Message);
}
}
}
public void Close()
{
if (Handle != null)
Handle.Close();
if (writeHandle != null)
writeHandle.Close();
Handle?.Close();
}
public String[] readAll()
public String[] ReadAllLines()
{
return Handle.ReadToEnd().Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
return Handle?.ReadToEnd().Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
}
public String getLines()
public String GetText()
{
return Handle.ReadToEnd();
return Handle?.ReadToEnd();
}
public String[] Tail(int lineCount)
@ -122,8 +66,6 @@ namespace SharedLibrary
private long sze;
private String Name;
private String _Directory;
private StreamReader Handle;
private StreamWriter writeHandle;
}
}