/// <summary> /// Converts data to its unencoded format /// </summary> /// <param name="From">Data</param> /// <param name="To">destination file (extension added automatically)</param> /// <returns>true, if successful</returns> public static bool Convert(byte[] From, string To) { FType FileType = WADfile.GetType(From); if (File.Exists(To)) { File.Delete(To); } switch (FileType) { //just copy the file for these case FType.XM: case FType.IT: case FType.MID: case FType.WAV: case FType.MP3: Program.Log(ConsoleColor.Green, "Copying DATA -> {0}", FileType); File.WriteAllBytes(To + "." + FileType.ToString(), From); break; case FType.OGG: Program.Log(ConsoleColor.Green, "Copying DATA -> {0}", FileType); File.WriteAllBytes(To + "." + FileType.ToString(), From); break; case FType.MUS: Program.Log(ConsoleColor.Yellow, "Converting MUS -> MID"); using (MemoryStream IN = new MemoryStream(From)) { using (FileStream OUT = File.Create(To + ".MID")) { MUS2MID.Convert(IN, OUT); } } break; case FType.RAWAUDIO: SaveAudio(From, To + ".WAV"); break; case FType.VIRTUAL: Program.Log(ConsoleColor.Yellow, "Not converting virtual entry"); return(false); default: try { ToImage(From, To + ".PNG"); } catch { return(false); } break; } return(true); }
private static void Convert(string From) { int last = From.LastIndexOfAny(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }); int dot = From.LastIndexOf('.'); string To = From; FType FileType = WADfile.GetType(File.ReadAllBytes(From)); //check if file has extension, if so, cut off if (dot > last) { To = From.Substring(0, dot); } if (FileType == FType.MUS) { To += ".MID"; } else if (FileType == FType.RAWAUDIO) { To += ".WAV"; } else { To += "." + FileType.ToString(); } //very simple check, if the destination is the same as the source, ignoring character case if (File.Exists(To) && WADfile.getHash(File.ReadAllBytes(From)) == WADfile.getHash(File.ReadAllBytes(To))) { Log(ConsoleColor.Yellow, "File would be identical after generating destination name. Not converting"); } else { Convert(From, To); } }
/// <summary> /// Converts data to its unencoded format /// </summary> /// <param name="From">Data</param> /// <param name="To">destination file (extension added automatically)</param> /// <returns>true, if successful</returns> public static bool Convert(byte[] From, string To) { FType FileType = GetDataType(From); if (File.Exists(To)) { Program.Log(Verbosity.Debug, "Deleting existing file {0}", To); File.Delete(To); } switch (FileType) { //just copy the file for these case FType.XM: case FType.IT: case FType.MID: case FType.WAV: case FType.MP3: case FType.OGG: Program.Log(Verbosity.Debug, "Copying DATA -> {0}", FileType); File.WriteAllBytes(To + "." + FileType.ToString(), From); break; case FType.MUS: Program.Log(Verbosity.Debug, "Converting MUS -> MID"); using (MemoryStream IN = new MemoryStream(From)) { using (FileStream OUT = File.Create(To + ".MID")) { MUS2MID.Convert(IN, OUT); } } break; case FType.RAWAUDIO: SaveAudio(From, To + ".WAV"); break; case FType.VIRTUAL: Program.Log(Verbosity.Debug, "Not converting virtual entry"); return(false); default: try { ToImage(From, To + ".PNG"); } catch { Program.Log(Verbosity.Log, "Unable to find suitable format for DATA. Skipping Convert()"); return(false); } break; } return(true); }
private static void Convert(string FromFile) { Log(Verbosity.Debug, "Converting {0} to auto generated name", FromFile); int last = FromFile.LastIndexOfAny(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }); int dot = FromFile.LastIndexOf('.'); string To = FromFile; FType FileType = WADfile.GetDataType(File.ReadAllBytes(FromFile)); //check if file has extension, if so, cut off if (dot > last) { To = FromFile.Substring(0, dot); } if (FileType == FType.MUS) { To += ".MID"; } else if (FileType == FType.RAWAUDIO) { To += ".WAV"; } else { To += "." + FileType.ToString(); } //very simple check, if the destination is the same as the source, ignoring character case if (File.Exists(To) && WADfile.getHash(File.ReadAllBytes(FromFile)) == WADfile.getHash(File.ReadAllBytes(To))) { Log(Verbosity.Warn, "File would be identical after generating destination name. Not converting"); } else { Log(Verbosity.Debug, "Auto-Generated File Name: {0}", To); Convert(FromFile, To); } }