Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- switch (Path.GetExtension(path).ToLowerInvariant())
- {
- case ".lip":
- try
- {
- SQLiteConnection sqlite = new SQLiteConnection("Data Source=" + path + ";Read Only=True");
- sqlite.Open();
- SQLiteCommand command = sqlite.CreateCommand();
- command.CommandText = "SELECT ImageData FROM CanvasPreview ORDER BY ImageWidth * ImageHeight DESC";
- using (SQLiteDataReader sqliteReader = command.ExecuteReader())
- if (sqliteReader.Read())
- using (MemoryStream mem = new MemoryStream(sqliteReader.GetBytes()))
- image = Image.FromStream(mem);
- sqlite.Close();
- }
- catch { }
- break;
- case ".clip":
- {
- byte[] sqliteData;
- using (FileStream stream = File.OpenRead(path))
- {
- using (BinaryReader reader = new BinaryReader(stream))
- {
- stream.Seek(0x30, SeekOrigin.Begin);
- long sqliteOffset = reader.ReadInt64BE();
- sqliteOffset += 0x10;
- stream.Seek(sqliteOffset, SeekOrigin.Begin);
- sqliteData = new byte[stream.Length - stream.Position];
- stream.Read(sqliteData, 0, sqliteData.Length);
- }
- }
- string temp = Path.GetTempFileName();
- try
- {
- File.WriteAllBytes(temp, sqliteData);
- using (SQLiteConnection sqlite = new SQLiteConnection("Data Source=" + temp))
- {
- sqlite.Open();
- using (SQLiteCommand command = sqlite.CreateCommand())
- {
- command.CommandText = "SELECT ImageData FROM CanvasPreview ORDER BY ImageWidth * ImageHeight DESC";
- using (SQLiteDataReader sqliteReader = command.ExecuteReader())
- if (sqliteReader.Read())
- using (MemoryStream mem = new MemoryStream(sqliteReader.GetBytes()))
- image = Image.FromStream(mem);
- }
- sqlite.Close();
- }
- }
- finally
- {
- SQLiteConnection.ClearAllPools();
- GC.Collect();
- GC.WaitForPendingFinalizers();
- if (File.Exists(temp))
- File.Delete(temp);
- }
- break;
- }
- default:
- using (FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read))
- image = Image.FromStream(file);
- break;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement