diff --git a/Phuse/CRC32.cs b/Phuse/CRC32.cs deleted file mode 100644 index be2f396..0000000 --- a/Phuse/CRC32.cs +++ /dev/null @@ -1,131 +0,0 @@ -using System; -using System.IO; -using System.Collections; -using System.Security.Cryptography; - -//------------------------------------------------------------- -// -// Fusenet - The Future of Usenet -// http://github.com/fusenet -// -// This library is free software; you can redistribute it -// and modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation. -// -//------------------------------------------------------------- - -namespace Phuse -{ - internal class CRC32 : HashAlgorithm // Phil Bolduc - { - private uint m_crc; - protected uint[] crc32Table; - - protected static bool autoCache; - protected static uint AllOnes = 0xffffffff; - protected static Hashtable cachedCRC32Tables; - - public CRC32() : this(DefaultPolynomial) { } - public CRC32(uint aPolynomial) : this(aPolynomial, CRC32.AutoCache) { } - - public uint[] CurrentTable { get { return crc32Table; } } - public static uint DefaultPolynomial { get { return 0x04C11DB7; } } - - public static bool AutoCache - { - get { return autoCache; } - set { autoCache = value; } - } - - static CRC32() - { - cachedCRC32Tables = Hashtable.Synchronized( new Hashtable() ); - autoCache = true; - } - - public static void ClearCache() - { - cachedCRC32Tables.Clear(); - } - - private static uint Reflect(uint val) - { - uint oval = 0; - for (int i=0; i<32; i++) - { - oval = (oval<<1) + (val&1); - val >>= 1; - } - return oval; - } - - protected static uint[] BuildCRC32Table( uint ulPolynomial ) - { - uint dwCrc; - uint[] table = new uint[256]; - - ulPolynomial = Reflect(ulPolynomial); - - for (int i = 0; i < 256; i++) - { - dwCrc = (uint)i; - for (int j = 8; j > 0; j--) - { - if((dwCrc & 1) == 1) - dwCrc = (dwCrc >> 1) ^ ulPolynomial; - else - dwCrc >>= 1; - } - table[i] = dwCrc; - } - - return table; - } - - public CRC32(uint aPolynomial, bool cacheTable) - { - this.HashSizeValue = 32; - - crc32Table = (uint []) cachedCRC32Tables[aPolynomial]; - if ( crc32Table == null ) - { - crc32Table = CRC32.BuildCRC32Table(aPolynomial); - if ( cacheTable ) - cachedCRC32Tables.Add( aPolynomial, crc32Table ); - } - Initialize(); - } - - public override void Initialize() - { - m_crc = AllOnes; - this.State = 0; - } - - protected override void HashCore(byte[] buffer, int offset, int count) - { - for (int i = offset; i < offset + count; i++) - { - ulong tabPtr = (m_crc & 0xFF) ^ buffer[i]; - m_crc >>= 8; - m_crc ^= crc32Table[tabPtr]; - } - - this.State = 1; - } - - protected override byte[] HashFinal() - { - byte [] finalHash = new byte [ 4 ]; - ulong finalCRC = m_crc ^ AllOnes; - - finalHash[0] = (byte) ((finalCRC >> 24) & 0xFF); - finalHash[1] = (byte) ((finalCRC >> 16) & 0xFF); - finalHash[2] = (byte) ((finalCRC >> 8) & 0xFF); - finalHash[3] = (byte) ((finalCRC >> 0) & 0xFF); - - this.State = 0; - return finalHash; - } - } -} // diff --git a/Phuse/README.md b/Phuse/README.md deleted file mode 100644 index 53b65ba..0000000 --- a/Phuse/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# fusenet -The Future of Usenet diff --git a/Phuse/API.cs b/src/API/API.cs similarity index 91% rename from Phuse/API.cs rename to src/API/API.cs index 894a0b7..515f795 100644 --- a/Phuse/API.cs +++ b/src/API/API.cs @@ -21,7 +21,11 @@ // //------------------------------------------------------------- -namespace Phuse +using Fusenet.Core; +using Fusenet.NNTP; +using Fusenet.Utils; + +namespace Fusenet.API { public interface Api { @@ -173,7 +177,7 @@ public string Send(string Newsgroup, List Command, CancellationTokenSour vSlot.Status = SlotStatus.Downloading; Notify(); - WaitHandle wRet = Module.WaitList(wList); + WaitHandle wRet = Common.WaitList(wList); if ((wRet == null) || (wRet.Handle == vToken.Token.WaitHandle.Handle)) { @@ -192,7 +196,7 @@ public string Send(string Newsgroup, List Command, CancellationTokenSour } else { - zOut = Module.TranslateStatus((int)vSlot.Status); + zOut = Common.TranslateStatus((int)vSlot.Status); } int vId = vSlot.ID; @@ -216,7 +220,7 @@ public string Send(string Newsgroup, List Command, CancellationTokenSour if (vFile.Output.Data.Length == 0) { continue; } vFile.Output.Data.Position = 0; - zOut = Module.GetString(vFile.Output.Data); + zOut = Common.GetString(vFile.Output.Data); } int vId = vSlot.ID; @@ -270,7 +274,7 @@ private void Notify() //internal class WebHandler : Phocus.Webhandler //{ - // private Phuse.Engine Engine; + // private Fusenet.Engine Engine; // internal WebHandler(Engine zEngine) // { @@ -442,13 +446,13 @@ internal static bool Slot(XmlWriter xR, VirtualSlot vSlot) { xR.WriteStartElement("slot"); xR.WriteElementString("nzo_id", Convert.ToString(vSlot.ID)); - xR.WriteElementString("name", Module.CleanString(vSlot.Name)); - xR.WriteElementString("filename", Module.CleanString(vSlot.Name)); - xR.WriteElementString("status", Module.TranslateStatus((int)vSlot.Status)); + xR.WriteElementString("name", Common.CleanString(vSlot.Name)); + xR.WriteElementString("filename", Common.CleanString(vSlot.Name)); + xR.WriteElementString("status", Common.TranslateStatus((int)vSlot.Status)); if (vSlot.Status == SlotStatus.Failed) { - xR.WriteElementString("fail_message", Module.CleanString(vSlot.StatusLine)); + xR.WriteElementString("fail_message", Common.CleanString(vSlot.StatusLine)); } if (!(vSlot.History)) @@ -457,21 +461,21 @@ internal static bool Slot(XmlWriter xR, VirtualSlot vSlot) int lSeconds = vInfo.SecondsLeft(vSlot.SpeedAverage, vSlot.TotalTime); string sLeft = "00:00:00"; - string ETA = Module.FormatDate(DateTime.UtcNow); + string ETA = Common.FormatDate(DateTime.UtcNow); if (lSeconds > 0) { - sLeft = Module.FormatElapsed(new TimeSpan(0, 0, lSeconds)); - ETA = Module.FormatDate(DateTime.UtcNow.AddSeconds(lSeconds)); + sLeft = Common.FormatElapsed(new TimeSpan(0, 0, lSeconds)); + ETA = Common.FormatDate(DateTime.UtcNow.AddSeconds(lSeconds)); } xR.WriteElementString("index", Convert.ToString(vSlot.Index)); xR.WriteElementString("percentage", Convert.ToString(Math.Round(vInfo.Percentage, 0))); xR.WriteElementString("bytes", Convert.ToString(vInfo.Expected)); xR.WriteElementString("kbpersec", String.Format(CultureInfo.InvariantCulture, "{0:0.00}", vSlot.Speed / (decimal)1000)); - xR.WriteElementString("mb", String.Format(CultureInfo.InvariantCulture, "{0:0.00}", Module.BytesToMegabytes(vInfo.Expected))); - xR.WriteElementString("mbleft", String.Format(CultureInfo.InvariantCulture, "{0:0.00}", Module.BytesToMegabytes(vInfo.BytesLeft))); - xR.WriteElementString("size", String.Format(CultureInfo.InvariantCulture, "{0:0.0}", Module.BytesToMegabytes(vInfo.Expected)) + " MB"); + xR.WriteElementString("mb", String.Format(CultureInfo.InvariantCulture, "{0:0.00}", Common.BytesToMegabytes(vInfo.Expected))); + xR.WriteElementString("mbleft", String.Format(CultureInfo.InvariantCulture, "{0:0.00}", Common.BytesToMegabytes(vInfo.BytesLeft))); + xR.WriteElementString("size", String.Format(CultureInfo.InvariantCulture, "{0:0.0}", Common.BytesToMegabytes(vInfo.Expected)) + " MB"); xR.WriteElementString("eta", ETA); xR.WriteElementString("timeleft", sLeft); xR.WriteElementString("priority", "Normal"); @@ -517,25 +521,25 @@ internal static bool Slots(XmlWriter xR, Slots vSlots) NNTPInfo vInfo = vSlots.Info; string sLeft = "00:00:00"; - string ETA = Module.FormatDate(DateTime.UtcNow); + string ETA = Common.FormatDate(DateTime.UtcNow); int lSeconds = vInfo.SecondsLeft(vSlots.SpeedAverage, vSlots.TotalTime); if (lSeconds > 0) { sLeft = new TimeSpan(0, 0, 0, lSeconds, 0).ToString("c"); - ETA = Module.FormatDate(DateTime.UtcNow.AddSeconds(lSeconds)); + ETA = Common.FormatDate(DateTime.UtcNow.AddSeconds(lSeconds)); } xR.WriteElementString("status", vSlots.Status); - xR.WriteElementString("paused", Module.BoolToString(vSlots.Paused)); - xR.WriteElementString("mb", String.Format(CultureInfo.InvariantCulture, "{0:0.00}", Module.BytesToMegabytes(Math.Abs(vInfo.Expected)))); - xR.WriteElementString("mbleft", String.Format(CultureInfo.InvariantCulture, "{0:0.00}", Module.BytesToMegabytes(Math.Abs(vInfo.BytesLeft)))); + xR.WriteElementString("paused", Common.BoolToString(vSlots.Paused)); + xR.WriteElementString("mb", String.Format(CultureInfo.InvariantCulture, "{0:0.00}", Common.BytesToMegabytes(Math.Abs(vInfo.Expected)))); + xR.WriteElementString("mbleft", String.Format(CultureInfo.InvariantCulture, "{0:0.00}", Common.BytesToMegabytes(Math.Abs(vInfo.BytesLeft)))); xR.WriteElementString("kbpersec", String.Format(CultureInfo.InvariantCulture, "{0:0.00}", vSlots.Speed / (decimal)1000)); xR.WriteElementString("eta", ETA); xR.WriteElementString("timeleft", sLeft); - xR.WriteElementString("uptime", Module.FormatElapsed(vSlots.Uptime)); + xR.WriteElementString("uptime", Common.FormatElapsed(vSlots.Uptime)); xR.WriteElementString("start", "0"); xR.WriteElementString("limit", "0"); xR.WriteElementString("speedlimit", "0"); @@ -545,8 +549,8 @@ internal static bool Slots(XmlWriter xR, Slots vSlots) if (vSlots.Log.Count > 0) { - string sWarning = Module.ReadLog(vSlots.Log, 1).Replace(Environment.NewLine, ""); - xR.WriteElementString("last_warning", Module.CleanString(sWarning)); + string sWarning = Common.ReadLog(vSlots.Log, 1).Replace(Environment.NewLine, ""); + xR.WriteElementString("last_warning", Common.CleanString(sWarning)); } // TODO Server.Log @@ -567,9 +571,9 @@ internal static bool Server(XmlWriter xR, VirtualServer vServer) xR.WriteElementString("nzo_id", Convert.ToString((vServer.ID))); xR.WriteElementString("host", vServer.Host); xR.WriteElementString("port", Convert.ToString(vServer.Port)); - xR.WriteElementString("ssl", Module.BoolToString(vServer.SSL)); - xR.WriteElementString("username", Module.CleanString(vServer.Username)); - xR.WriteElementString("password", Module.Repeat("*", vServer.Password.Length)); + xR.WriteElementString("ssl", Common.BoolToString(vServer.SSL)); + xR.WriteElementString("username", Common.CleanString(vServer.Username)); + xR.WriteElementString("password", Common.Repeat("*", vServer.Password.Length)); xR.WriteElementString("priority", TranslatePriority(vServer.Priority)); xR.WriteElementString("connections", Convert.ToString(vServer.Connections.Count(vServer.ID))); xR.WriteEndElement(); diff --git a/Phuse/Engine.cs b/src/Core/Engine.cs similarity index 98% rename from Phuse/Engine.cs rename to src/Core/Engine.cs index c54a651..ca2f454 100644 --- a/Phuse/Engine.cs +++ b/src/Core/Engine.cs @@ -7,6 +7,7 @@ using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; +using Fusenet.API; //------------------------------------------------------------- // @@ -19,7 +20,7 @@ // //------------------------------------------------------------- -namespace Phuse +namespace Fusenet.Core { public class Engine { diff --git a/Phuse/Scheduler.cs b/src/Core/Scheduler.cs similarity index 93% rename from Phuse/Scheduler.cs rename to src/Core/Scheduler.cs index f25f984..0746024 100644 --- a/Phuse/Scheduler.cs +++ b/src/Core/Scheduler.cs @@ -4,9 +4,9 @@ using System.Text; using System.Linq; using System.Threading; +using System.Diagnostics; using System.Collections.Generic; using System.Collections.Concurrent; -using System.Diagnostics; //------------------------------------------------------------- // @@ -19,15 +19,19 @@ // //------------------------------------------------------------- -namespace Phuse +using Fusenet.API; +using Fusenet.NNTP; +using Fusenet.Utils; + +namespace Fusenet.Core { internal class Scheduler { internal Connections Connections; internal Slots Slots = new Slots(); - private IndexedCollection zStacks = new IndexedCollection(); - private IndexedCollection zServers = new IndexedCollection(); + private Utils.IndexedCollection zStacks = new Utils.IndexedCollection(); + private Utils.IndexedCollection zServers = new Utils.IndexedCollection(); internal Scheduler() { @@ -40,7 +44,7 @@ internal Scheduler() } public int Count { get { return zServers.Count; } } - private IndexedCollection Servers { get { return zServers; } } + private Utils.IndexedCollection Servers { get { return zServers; } } //internal List ListSID() { return zServers.SIDList(-1); } private bool SlotExist(int SlotID) { return (Slots.ContainsKey(SlotID)); } private bool StackExist(int ServerID) { return zStacks.ContainsKey(ServerID); } @@ -88,7 +92,7 @@ internal bool Remove(int ServerID = -1) // return Remove(zServers.GetID(ServerSID)); //} - internal IndexedCollection Stack(int ServerID, int SlotID) + internal Utils.IndexedCollection Stack(int ServerID, int SlotID) { if (!SlotExist(SlotID)) { return null; } if (Servers.Item(ServerID) == null) { return null; } @@ -109,9 +113,9 @@ internal bool Close() return true; } - internal IndexedCollection SwitchStack(int SlotID, VirtualConnection vConnection) + internal Utils.IndexedCollection SwitchStack(int SlotID, VirtualConnection vConnection) { - IndexedCollection iStack = null; + Utils.IndexedCollection iStack = null; List AvailableStacks = null; while(true) @@ -218,16 +222,16 @@ private List WaitingSlots } } - private List WaitingStacks(int ServerID) + private List WaitingStacks(int ServerID) { - List cList = new List(); + List cList = new List(); if (!StackExist(ServerID)) { return cList; } if (!ServerActive(ServerID)) { return cList; } foreach (VirtualSlot vSlot in RandomSlots()) { - IndexedCollection tStack = Stack(ServerID, vSlot.ID); + Utils.IndexedCollection tStack = Stack(ServerID, vSlot.ID); if ((tStack != null) && (!tStack.IsEmpty)) { cList.Add(tStack); } } @@ -243,7 +247,7 @@ private List RandomSlots() while (iList.Count > 0) { - int RandomID = iList[Module.Random.Next(0, iList.Count - 1)]; + int RandomID = iList[Utils.Common.Random.Next(0, iList.Count - 1)]; VirtualSlot vSlot = Slots.Item(RandomID); @@ -299,7 +303,7 @@ internal string XML get { StringBuilder sX = new StringBuilder(); - XmlWriter xR = Module.CreateWriter(sX); + XmlWriter xR = Common.CreateWriter(sX); if (!(WriteXML(xR))) { return ""; } @@ -373,29 +377,29 @@ public string Log private string lDebug { - get { return Module.ReadLog(DebugLog, 500); } + get { return Common.ReadLog(DebugLog, 500); } } private string lStatus { - get { return Module.ReadLog(StatusLog, 500); } + get { return Common.ReadLog(StatusLog, 500); } } internal void WriteDebug(string sCode, string sMsg) { //Debug.WriteLine("Debug: " + sMsg); - DebugLog.Enqueue(Module.MakeMsg(sCode, sMsg)); + DebugLog.Enqueue(Common.MakeMsg(sCode, sMsg)); } internal void WriteStatus(string sMsg) { //Debug.WriteLine("Status: " + sMsg); - StatusLog.Enqueue(Module.MakeMsg("000", sMsg)); + StatusLog.Enqueue(Common.MakeMsg("000", sMsg)); } internal void LogError(int CommandID, NNTPError zErr) { - WriteStatus("Command #" + Convert.ToString(CommandID) + " - Error " + Module.MakeErr(zErr)); + WriteStatus("Command #" + Convert.ToString(CommandID) + " - Error " + Common.MakeErr(zErr)); } internal bool WriteXML(XmlWriter xR) diff --git a/Phuse/Slots.cs b/src/Core/Slots.cs similarity index 96% rename from Phuse/Slots.cs rename to src/Core/Slots.cs index 19673a5..78c278e 100644 --- a/Phuse/Slots.cs +++ b/src/Core/Slots.cs @@ -1,11 +1,11 @@ using System; +using System.Xml; using System.Linq; -using System.Collections.Generic; using System.Text; -using System.Collections.Concurrent; using System.Threading; -using System.Xml; using System.Diagnostics; +using System.Collections.Generic; +using System.Collections.Concurrent; //------------------------------------------------------------- // @@ -18,7 +18,12 @@ // //------------------------------------------------------------- -namespace Phuse +using Fusenet.API; +using Fusenet.Core; +using Fusenet.NNTP; +using Fusenet.Utils; + +namespace Fusenet.Core { internal class Slots : VirtualItem { @@ -34,8 +39,8 @@ internal Slots() } public int Count { get { return zCol.Count; } } - internal string XML { get { return Module.XmlToString(this); } } - public NNTPInfo Info { get { return Module.CountInfo(VirtualList); } } + internal string XML { get { return Common.XmlToString(this); } } + public NNTPInfo Info { get { return Common.CountInfo(VirtualList); } } internal bool ContainsKey(int SlotID) { return zCol.ContainsKey(SlotID); } internal List ListID(int SlotID = -1) { return zCol.KeyList(SlotID); } internal VirtualSlot Item(int SlotID) { return (VirtualSlot)zCol.Item(SlotID); } @@ -243,7 +248,7 @@ public int Index public int Count { get { return zCol.Count; } } public long TotalTime { get { return zStats.TotalTime; } } public ManualResetEventSlim WaitHandle { get { return zWait; } } - public NNTPInfo Info { get { return Module.CountInfo(VirtualList); } } + public NNTPInfo Info { get { return Common.CountInfo(VirtualList); } } public bool WriteXML(XmlWriter xR) { return (ApiXML.Slot(xR, this)); } internal void Progress(long AddedBytes) { zStats.Progress(AddedBytes); } internal List ListID(int FileID = -1) { return zCol.KeyList(FileID); } @@ -428,7 +433,7 @@ internal VirtualFile(string sName, List cList) internal NNTPOutput Output { get { return zOutput; } } internal bool IsCompleted { get { return zCol.IsCompleted; } } public List VirtualList { get { return null; } } - internal string Log { get { return Module.ReadLog(ErrorLog, 50); } } + internal string Log { get { return Common.ReadLog(ErrorLog, 50); } } public int Count { get { return (int)Interlocked.Read(ref zTotal); } } internal void Progress(long AddedBytes) { zStats.Progress(AddedBytes); } internal bool Remove(int CommandID = -1) { return zCol.Remove(CommandID); } @@ -474,7 +479,7 @@ private bool Add(List cList) if (cList == null) { return false; } if (cList.Count == 0) { return false; } - Module.Safe32(ref zTotal, cList.Count); + Common.Safe32(ref zTotal, cList.Count); cList.Sort(); @@ -495,7 +500,7 @@ private bool Add(List cList) } - Module.Safe32(ref zExpected, cSize); + Common.Safe32(ref zExpected, cSize); zCol = new IndexedCollection(cOut); return true; } @@ -510,7 +515,7 @@ internal void LogError(int CommandID, NNTPError zErr) //Debug.WriteLine(Module.MakeMsg(Convert.ToString(zErr.Code), "Command #" + Convert.ToString(CommandID) + " - Error " + Module.MakeErr(zErr))); Errors.Enqueue(zErr.Message.Replace(Environment.NewLine, "")); - ErrorLog.Enqueue(Module.MakeMsg(Convert.ToString(zErr.Code), "Command #" + Convert.ToString(CommandID) + " - Error " + Module.MakeErr(zErr))); + ErrorLog.Enqueue(Common.MakeMsg(Convert.ToString(zErr.Code), "Command #" + Convert.ToString(CommandID) + " - Error " + Common.MakeErr(zErr))); } } } // \ No newline at end of file diff --git a/Phuse/Phuse.csproj b/src/Fusenet.csproj similarity index 76% rename from Phuse/Phuse.csproj rename to src/Fusenet.csproj index 5ff98f1..c8775cc 100644 --- a/Phuse/Phuse.csproj +++ b/src/Fusenet.csproj @@ -11,13 +11,12 @@ Properties - Phuse + Fusenet Fusenet 512 WindowsForms - v4.5 - - + v4.0 + Client x86 @@ -55,19 +54,20 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + +