Skip to content

Commit

Permalink
code cleanup & optimizations.
Browse files Browse the repository at this point in the history
  • Loading branch information
stavrossk committed Oct 11, 2012
1 parent 0873af8 commit ad87830
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 40 deletions.
10 changes: 7 additions & 3 deletions Code/Directory Scanner/DirectoryScanner.cs
Expand Up @@ -3,7 +3,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
using EMA.Core;
using EMA.ImportingEngine;
Expand Down Expand Up @@ -108,7 +107,11 @@ var allfiles
}
catch (Exception e)
{
Debugger.LogMessageToFile(e.ToString());

Debugger
.LogMessageToFile
(e.ToString());

}

return true;
Expand Down Expand Up @@ -210,7 +213,8 @@ private static int CalculateTotalDirectoryCount
{

dirsTotal = GetDirectoryCount
(importRootFolder, ref currentDir);
(importRootFolder,
ref currentDir);


}
Expand Down
75 changes: 65 additions & 10 deletions Code/Directory Scanner/RecursiveDirectoryScanner.cs
Expand Up @@ -7,12 +7,20 @@
using EMA.ImportingEngine;
using MeediOS;



namespace EMA.MediaSnapshotEngine
{




class RecursiveDirectoryScanner
{




internal static bool ScanDirectoryRecursively
(
string strDir,
Expand All @@ -31,12 +39,18 @@ IEnumerable<string> videoExtensionsCommon
{


MainImportingEngine.GeneralStatus = "Performing media importing...";
MainImportingEngine.GeneralStatus
= "Performing media importing...";



if (Helpers.UserCancels("Scanning directory " + strDir + "..."))
if (Helpers.UserCancels
("Scanning directory "
+ strDir + "..."))
return false;



if (!DirectoryScanner
.ImportFilesFromDirectory
(strDir,
Expand All @@ -58,18 +72,38 @@ IEnumerable<string> videoExtensionsCommon
return false;


IEnumerable<string> directories = new BindingList<string>();
IEnumerable<string> directories
= new BindingList<string>();



try
{
directories = GetSubDirectories(strDir);

directories
= GetSubDirectories
(strDir);


}
catch (PathTooLongException e)
{
MessageBox.Show(@"Path too long");
Debugger.LogMessageToFile("[Directory scanner] An unexpected error occured while the Directory scanner" +
" was trying to retrieve sub-directories of the directory " + strDir +
". The error was: " + e);


//MessageBox.Show
// (@"Path too long");


Debugger.LogMessageToFile
("[Directory scanner]" +
" An unexpected error occured " +
"while the Directory scanner" +
" was trying to retrieve " +
"sub-directories of the directory "
+ strDir +
". The error was: " + e);


}


Expand All @@ -93,23 +127,41 @@ IEnumerable<string> videoExtensionsCommon
}


private static IEnumerable<string> GetSubDirectories(string strDir)
private static IEnumerable<string>
GetSubDirectories
(string strDir)
{


string[] directories;

try
{
directories = Directory.GetDirectories(strDir);


directories
= Directory
.GetDirectories
(strDir);


}
catch
{
return null;
}



return directories;
}







//TODO: make all these parameters a struct
private static bool ScanSubDirectories
(IMLSection moviesSection,
Expand Down Expand Up @@ -202,4 +254,7 @@ internal static bool ScanSubDirectoriesAndImportMediaFiles

}




}
@@ -1,6 +1,6 @@
//'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
//'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
//'' Easy Media Adder for Meedio/MeediOS ''
//'' Easy Film Importer for Meedio/MeediOS ''
//'' Copyright (C) 2008-2012 Stavros Skamagkis ''
//'' ''
//'' This program is free software: you can redistribute it and/or modify ''
Expand Down
20 changes: 16 additions & 4 deletions Code/File Metadata Extractors/VideoFilenameCleaner.cs
Expand Up @@ -83,11 +83,17 @@ private static string RemoveTagsFromFilename
}



if (releaseIndex > 0)
filename = filename.Substring(0, releaseIndex);
filename = filename.Substring
(0, releaseIndex);



filename = filename.Trim();



return filename;
}

Expand All @@ -109,13 +115,18 @@ string pluginPath


Helpers.UpdateProgress
("","Loading filename cleaner dictionaries...");
("","Loading filename " +
"cleaner dictionaries...");


Debugger.LogMessageToFile
("Loading filename cleaner dictionaries...");
("Loading filename " +
"cleaner dictionaries...");


string dictionaryPath
= pluginPath + @"Video filename cleaner dictionary\";
= pluginPath +
@"Video filename cleaner dictionary\";



Expand Down Expand Up @@ -144,6 +155,7 @@ string dictionaryPath

}
catch (Exception e)

{

Helpers.UpdateProgress
Expand Down
3 changes: 2 additions & 1 deletion Code/Media Section Populator/MediaSectionPopulator.cs
Expand Up @@ -125,7 +125,8 @@ private static void ImportVideo



private static bool AdhereToVideoFilesizeThreshold(FileInfo file)
private static bool AdhereToVideoFilesizeThreshold
(FileInfo file)
{


Expand Down
69 changes: 59 additions & 10 deletions Code/Media Section Populator/MediaSectionPopulatorHelpers.cs
Expand Up @@ -2,9 +2,13 @@
using System.IO;
using System.Windows.Forms;



namespace EMA.MediaSnapshotEngine
{



internal class MediaSectionPopulatorHelpers
{

Expand All @@ -13,13 +17,22 @@ internal class MediaSectionPopulatorHelpers

internal static bool ProceedToImportMovie(FileInfo file)
{


Application.DoEvents();

bool videoIsLocatedInAMovieFolder = VideoIsLocatedInAMovieFolder(file);

bool videoIsLocatedInAMovieFolder
= VideoIsLocatedInAMovieFolder(file);


Application.DoEvents();

bool proceedToImport = videoIsLocatedInAMovieFolder;

bool proceedToImport
= videoIsLocatedInAMovieFolder;




return proceedToImport;
Expand All @@ -31,34 +44,70 @@ internal static bool ProceedToImportMovie(FileInfo file)



internal static bool VideoIsLocatedInAMovieFolder(FileSystemInfo file)
internal static bool VideoIsLocatedInAMovieFolder
(FileSystemInfo file)
{

Application.DoEvents();

bool isFilm = false;

foreach (string filmsFolder in Settings.FilmsFolders)

foreach (string filmsFolder
in Settings.FilmsFolders)
{
if (String.IsNullOrEmpty(filmsFolder)) continue;

if (!file.FullName.Contains(filmsFolder)) continue;

if (String.IsNullOrEmpty
(filmsFolder))
continue;



if (!file.FullName
.Contains
(filmsFolder))
continue;



Debugger.LogMessageToFile(
"This video file is contained in the specified films root directory and will be considered to be a film.");
"This video file is contained" +
" in the specified films root directory" +
" and will be considered to be a film.");


isFilm = true;


}


Application.DoEvents();

return isFilm;
}

internal static bool SkipTrailer(FileSystemInfo file)



internal static bool
SkipTrailer
(FileSystemInfo file)
{
string fileNameWoExt = file.Name.Replace(file.Extension, "");

return fileNameWoExt.EndsWith("-trailer");

string fileNameWoExt
= file.Name.Replace
(file.Extension, "");



return fileNameWoExt
.EndsWith
("-trailer");


}


Expand Down

0 comments on commit ad87830

Please sign in to comment.