297 lines
9.6 KiB
C#
297 lines
9.6 KiB
C#
using System.Drawing;
|
|
using System.Text;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Navigation;
|
|
using System.Windows.Shapes;
|
|
using file_finder__test;
|
|
using ShadowStream;
|
|
using ShadowStream.LogHelper;
|
|
using ShadowStream.Obejeckte;
|
|
using System.IO;
|
|
using System.Threading;
|
|
using ShadowStream.ObjecktForJason;
|
|
using TagLib;
|
|
using ShadowStream.Modules;
|
|
using ShadowStream.ObjecktForJason;
|
|
|
|
|
|
namespace ModuleManager;
|
|
|
|
/// <summary>
|
|
/// Interaction logic for MainWindow.xaml
|
|
/// </summary>
|
|
//Quinn and Reda and Yazan
|
|
public partial class MainWindow : Window
|
|
{
|
|
//adding base components used threw out the code
|
|
private static LogHelper loghelper = new LogHelper();
|
|
LogWindow log = new LogWindow(loghelper.GetEntries());
|
|
|
|
private Catagory Muvie = new Catagory("Muvie");
|
|
private Catagory Serie = new Catagory("Serie");
|
|
private Catagory Music = new Catagory("Music");
|
|
private Catagory Photo = new Catagory("Photos");
|
|
|
|
List<string> suportedVidioFiles = new List<string>();
|
|
List<string> suportedMusicFiles = new List<string>();
|
|
List<string> suportedPhotoFiles = new List<string>();
|
|
|
|
//root directory
|
|
List<string> dirs = new List<string>();
|
|
private int option =0;
|
|
int specificOption = 0;
|
|
string rootPath = "C:/Users/bib/Desktop/";
|
|
|
|
FileScanner fileScanner;
|
|
//code start
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
//Initialise but Hide
|
|
log.Hide();
|
|
this.Hide();
|
|
//Begin Login Process
|
|
var login = new LogIn();
|
|
login.Show();
|
|
//adding all extensions... example values added
|
|
suportedVidioFiles.Add("mp4");
|
|
suportedVidioFiles.Add("mkv");
|
|
suportedMusicFiles.Add("wav");
|
|
suportedMusicFiles.Add("mp3");
|
|
suportedPhotoFiles.Add("jpg");
|
|
Createscan();
|
|
dirs.Add("C:/");
|
|
|
|
//execute and wait for task completion
|
|
var tmp = fileScanner.ScanAllDrivesAsync();
|
|
|
|
//load json parallel to finding drives
|
|
//add code laiter
|
|
|
|
tmp.Wait();
|
|
foreach (var VARIABLE in tmp.Result)
|
|
{
|
|
dirs.Add(VARIABLE);
|
|
}
|
|
|
|
|
|
}
|
|
void Createscan()
|
|
{
|
|
//adding all string arrays to one temp array to do the initial scan of the designated drive
|
|
int count = 0;
|
|
string[] tmp = new string[suportedMusicFiles.Count + suportedVidioFiles.Count + suportedPhotoFiles.Count];
|
|
foreach (var suportedVidioFile in suportedVidioFiles)
|
|
{
|
|
tmp[count] = suportedVidioFile;
|
|
count++;
|
|
}
|
|
|
|
foreach (var suportedMusicFile in suportedMusicFiles)
|
|
{
|
|
tmp[count] = suportedMusicFile;
|
|
count++;
|
|
}
|
|
|
|
foreach (var suportedPhotoFile in suportedPhotoFiles)
|
|
{
|
|
tmp[count] = suportedPhotoFile;
|
|
count++;
|
|
}
|
|
//initialise the file scanner with all files endings wanted
|
|
fileScanner = new FileScanner(tmp);
|
|
}
|
|
|
|
|
|
//btn logic
|
|
void scanButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
List<string> tmp = new List<string>();
|
|
switch (option)
|
|
{
|
|
case 0:
|
|
foreach (var VARIABLE in dirs)
|
|
{
|
|
foreach (var tmp2 in fileScanner.ScanDriveParallel(VARIABLE).Result)
|
|
{
|
|
tmp.Add(tmp2);
|
|
}
|
|
}
|
|
break;
|
|
case 1:
|
|
foreach (var VARIABLE in fileScanner.ScanDriveParallel(dirs[specificOption]).Result)
|
|
{
|
|
tmp.Add(VARIABLE);
|
|
}
|
|
|
|
break;
|
|
case 2:
|
|
foreach (var VARIABLE in fileScanner.ScanDriveParallel(rootPath).Result)
|
|
{
|
|
tmp.Add(VARIABLE);
|
|
}
|
|
break;
|
|
}
|
|
|
|
var classifier = new FileClassifier();
|
|
var (musicFiles, videoFiles,photoFiles) = classifier.ClassifyFilesAsync(tmp, suportedMusicFiles,suportedVidioFiles,suportedPhotoFiles ).Result;
|
|
|
|
var separator = new VideoSeparator();
|
|
var (series, movies) = separator.SeparateVideosAsync(videoFiles).Result;
|
|
//causes delibrit null refrence exeption. so dont use it!!! :-P
|
|
videoFiles = null;
|
|
//music list,muvie list,photo list,music list
|
|
//add to catagory
|
|
List<locJason> muviesJS = new List<locJason>();
|
|
List<locJason> seriesJS = new List<locJason>();
|
|
List<locJason> photosJS = new List<locJason>();
|
|
List<locJason> mucicJS = new List<locJason>();
|
|
|
|
JasonToString jasonToString = new JasonToString();
|
|
|
|
foreach (var VARIABLE in ItemCreater(movies, "Muvie",false))
|
|
{
|
|
Muvie.addItem(VARIABLE);
|
|
|
|
muviesJS.Add(new locJason());
|
|
muviesJS[muviesJS.Count - 1].path = VARIABLE.getLink();
|
|
muviesJS[muviesJS.Count - 1].imageData = jasonToString.BitmapToBase64String(BitmapImageToBitmap(VARIABLE.getImage()));
|
|
muviesJS[muviesJS.Count - 1].type = VARIABLE.getType();
|
|
}
|
|
foreach (var VARIABLE in ItemCreater(series, "Serie",false))
|
|
{
|
|
Serie.addItem(VARIABLE);
|
|
|
|
seriesJS[muviesJS.Count - 1].path = VARIABLE.getLink();
|
|
seriesJS[muviesJS.Count - 1].imageData = jasonToString.BitmapToBase64String(BitmapImageToBitmap(VARIABLE.getImage()));
|
|
seriesJS[muviesJS.Count - 1].type = VARIABLE.getType();
|
|
}
|
|
foreach (var VARIABLE in ItemCreater(photoFiles, "Photo",true))
|
|
{
|
|
Photo.addItem(VARIABLE);
|
|
|
|
photosJS[muviesJS.Count - 1].path = VARIABLE.getLink();
|
|
photosJS[muviesJS.Count - 1].imageData = jasonToString.BitmapToBase64String(BitmapImageToBitmap(VARIABLE.getImage()));
|
|
photosJS[muviesJS.Count - 1].type = VARIABLE.getType();
|
|
}
|
|
foreach (var VARIABLE in ItemCreater(musicFiles, "Msuic",false,true))
|
|
{
|
|
Music.addItem(VARIABLE);
|
|
|
|
mucicJS[muviesJS.Count - 1].path = VARIABLE.getLink();
|
|
mucicJS[muviesJS.Count - 1].imageData = jasonToString.BitmapToBase64String(BitmapImageToBitmap(VARIABLE.getImage()));
|
|
mucicJS[muviesJS.Count - 1].type = VARIABLE.getType();
|
|
}
|
|
|
|
|
|
//locJson
|
|
Jason_Writer jason_Writer = new Jason_Writer();
|
|
List<Task> tasks = new List<Task>();
|
|
tasks.Add(jason_Writer.SaveList("Muvies", muviesJS));
|
|
tasks.Add(jason_Writer.SaveList("Series", seriesJS));
|
|
tasks.Add(jason_Writer.SaveList("Photos", photosJS));
|
|
tasks.Add(jason_Writer.SaveList("Music", mucicJS));
|
|
|
|
Task.WhenAll(tasks).Wait();
|
|
|
|
//next up the db json
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
List<Item> ItemCreater(List<string> path, string type,bool isFoto)
|
|
{
|
|
List<Item> items = new List<Item>();
|
|
|
|
foreach (var VARIABLE in path)
|
|
{
|
|
Bitmap frame200;
|
|
if(!isFoto)
|
|
frame200 = VideoFrameExtractor.GetFrame200(VARIABLE);
|
|
else
|
|
{
|
|
frame200 = new Bitmap(VARIABLE);
|
|
}
|
|
items.Add(new Item(VARIABLE, type,ConvertBitmapToBitmapImage(frame200), isFoto));
|
|
}
|
|
|
|
return items;
|
|
}
|
|
List<Item> ItemCreater(List<string> paths, string type, bool isFoto, bool Music)
|
|
{
|
|
List<Item> items = new List<Item>();
|
|
Bitmap defaultImage = new Bitmap("default music picture.png");
|
|
|
|
foreach (var filePath in paths)
|
|
{
|
|
Bitmap bitmap = defaultImage;
|
|
|
|
try
|
|
{
|
|
var file = TagLib.File.Create(filePath);
|
|
if (file.Tag.Pictures.Length > 0)
|
|
{
|
|
var pic = file.Tag.Pictures[0];
|
|
// MemoryStream lets you work with data stored in memory like a file or stream.
|
|
using (var ms = new MemoryStream(pic.Data.Data))
|
|
{
|
|
bitmap = new Bitmap(ms);
|
|
}
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
// If anything fails, keep default image
|
|
}
|
|
|
|
items.Add(new Item(filePath, type, ConvertBitmapToBitmapImage(bitmap), isFoto));
|
|
}
|
|
|
|
return items;
|
|
}
|
|
|
|
public static BitmapImage ConvertBitmapToBitmapImage(System.Drawing.Bitmap bitmap)
|
|
{
|
|
using (var memory = new System.IO.MemoryStream())
|
|
{
|
|
bitmap.Save(memory, System.Drawing.Imaging.ImageFormat.Png);
|
|
memory.Position = 0;
|
|
|
|
var bitmapImage = new BitmapImage();
|
|
bitmapImage.BeginInit();
|
|
bitmapImage.StreamSource = memory;
|
|
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
|
|
bitmapImage.EndInit();
|
|
bitmapImage.Freeze(); // Optional: for thread safety
|
|
|
|
return bitmapImage;
|
|
}
|
|
}
|
|
public static Bitmap BitmapImageToBitmap(BitmapImage bitmapImage)
|
|
{
|
|
using (MemoryStream ms = new MemoryStream())
|
|
{
|
|
// Encode BitmapImage to stream (e.g., PNG)
|
|
BitmapEncoder encoder = new PngBitmapEncoder();
|
|
encoder.Frames.Add(BitmapFrame.Create(bitmapImage));
|
|
encoder.Save(ms);
|
|
|
|
ms.Seek(0, SeekOrigin.Begin); // Reset stream position
|
|
|
|
// Create Bitmap from stream
|
|
return new Bitmap(ms);
|
|
}
|
|
}
|
|
|
|
|
|
//scan logic
|
|
|
|
} |