public static ConfigV0 Read(byte[] ar, int magic) { ConfigV0 ret = new ConfigV0(); ret.activeProfile = magic; ret.profiles = DeSerializer.DeSerialize <List <ProfileV0> >(ar); return(ret); }
public static bool Read() { FileStream fs; try { fs = new FileStream(filepath, FileMode.Open); long sizeLong = fs.Length; if (sizeLong > 2100000000) { throw new OverflowException("Config file is too large to read."); } int size = (int)fs.Length; byte[] ar = new byte[size], ar2 = new byte[size - 4]; fs.Read(ar, 0, size); fs.Close(); Array.Copy(ar, 4, ar2, 0, ar2.Length); int magic = BitConverter.ToInt32(ar, 0); if (ConfigV3.Check(magic)) { cfg = ConfigV3.Read(ar2, magic); } else if (ConfigV2.Check(magic)) { cfg = ConfigV2.Read(ar2, magic).Convert(); } else if (ConfigV1.Check(magic)) { cfg = ConfigV1.Read(ar2, magic).Convert().Convert(); } else { cfg = ConfigV0.Read(ar2, magic).Convert().Convert().Convert(); } return(true); } catch { // unable to read cfg = null; return(false); } }