53 lines
1.4 KiB
C#
53 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.IO;
|
|
|
|
namespace RadioBroadcaster.Server
|
|
{
|
|
static class FileEngine
|
|
{
|
|
static string[] WriteBuffer = new string[1024];
|
|
static int LastWrite = -1;
|
|
static int LastAddition = -1;
|
|
static bool IsCurrentlyActive = false;
|
|
public static string logLocation = "";
|
|
public static void Write(string TextToWrite)
|
|
{
|
|
LastAddition = LastAddition + 1;
|
|
if(LastAddition > 1023)
|
|
{
|
|
LastAddition = 0;
|
|
}
|
|
WriteBuffer[LastAddition] = TextToWrite;
|
|
if (!IsCurrentlyActive)
|
|
{
|
|
|
|
}
|
|
}
|
|
static void WriteManager()
|
|
{
|
|
FileStream fs = File.OpenWrite(logLocation);
|
|
fs.Position = fs.Length; // Set position to the end of the stream.
|
|
while(LastWrite != LastAddition)
|
|
{
|
|
DoWrite(fs);
|
|
}
|
|
fs.Close();
|
|
IsCurrentlyActive = false;
|
|
}
|
|
static void DoWrite(FileStream fileStream)
|
|
{
|
|
LastWrite = LastWrite + 1;
|
|
if(LastWrite > 1023)
|
|
{
|
|
LastWrite = 0;
|
|
}
|
|
byte[] utf8Bytes = Encoding.UTF8.GetBytes(WriteBuffer[LastWrite]);
|
|
fileStream.Write(utf8Bytes, 0, utf8Bytes.Length);
|
|
}
|
|
}
|
|
}
|