Skip to content

Commit

Permalink
Release update to version 4, fixes #114 and #112
Browse files Browse the repository at this point in the history
  • Loading branch information
HerbL27 committed Aug 24, 2018
1 parent 2cdee05 commit 44c4f9d
Show file tree
Hide file tree
Showing 20 changed files with 360 additions and 211 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
2018.08.24 | FileMasta 4.1

CHANGE: CORE | Fixed #114
CHANGE: CORE | Fixed #112
CHANGE: CORE | Improved code efficiency
CHANGE: CORE | Added error retry attempts
CHANGE: UI | Re-added external search engines
CHANGE: UI | Minor interface adjustments




2018.06.28 | FileMasta 4.0

CHANGE: CORE | Datatabase now uses FTP servers/files
CHANGE: CORE | Improved crawler, faster and more efficient
CHANGE: CORE | All file extensions/types supported
CHANGE: UI | Standard winform interface
CHANGE: UI | Added right-click options to files
CHANGE: UI | Added boomarks window,
CHANGE: UI | Added boomarks window
CHANGE: UI | Added menu and status toolbar
CHANGE: UI | Added browsers to external apps

Expand Down
2 changes: 1 addition & 1 deletion FileMasta/Extensions/ImageExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static Bitmap ChangeColor(Bitmap scrBitmap, Color newColor)
}
return newBitmap;
}
catch (Exception ex) { Program.log.Error("Error changing image colour", ex); return null; }
catch (Exception ex) { Program.Log.Error("Error changing image colour", ex); return null; }
}
}
}
4 changes: 0 additions & 4 deletions FileMasta/Extensions/LocalExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ class LocalExtensions
public static string PathRoot { get; } = $@"{Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)}\FileMasta\";
public static string PathData { get; } = $@"{PathRoot}Data\";
public static string PathDownloadsDirectory { get; } = $@"{KnownFolders.GetPath(KnownFolder.Downloads)}\";
public static string PathVideosDirectory { get; } = $@"{KnownFolders.GetPath(KnownFolder.Videos)}\";
public static string PathMusicDirectory { get; } = $@"{KnownFolders.GetPath(KnownFolder.Music)}\";
public static string PathDocumentsDirectory { get; } = $@"{KnownFolders.GetPath(KnownFolder.Documents)}\";
public static string PathDesktopDirectory { get; } = $@"{KnownFolders.GetPath(KnownFolder.Desktop)}\";
public static string PathBookmarks { get; } = $@"{PathRoot}bookmarked.json";

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion FileMasta/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,4 @@ public static bool IsValidJSON(string json)
}
}
}
}
}
2 changes: 1 addition & 1 deletion FileMasta/FileMasta.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Extensions\ImageExtensions.cs" />
<Compile Include="Windows\FileDetailsWindow.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Windows\FileDetailsWindow.Designer.cs">
<DependentUpon>FileDetailsWindow.cs</DependentUpon>
</Compile>
<Compile Include="Extensions\ImageExtensions.cs" />
<Compile Include="Windows\AboutWindow.cs">
<SubType>Form</SubType>
</Compile>
Expand Down
10 changes: 5 additions & 5 deletions FileMasta/Files/Bookmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static bool IsBookmarked(string url)
/// <returns>Bookmark item as a WebFile</returns>
public static List<FtpFile> BookmarkedFiles()
{
Program.log.Info("Getting users bookmarks files");
Program.Log.Info("Getting users bookmarks files");

var filesBookmarks = new List<FtpFile>();
if (File.Exists(LocalExtensions.PathBookmarks))
Expand All @@ -72,10 +72,10 @@ public static List<FtpFile> BookmarkedFiles()
}
catch (Exception ex)
{
Program.log.Error("Unable to get bookmarks", ex);
Program.Log.Error("Unable to get bookmarks", ex);
}

Program.log.Info("Users bookmarks returned successful");
Program.Log.Info("Users bookmarks returned successful");

return filesBookmarks;
}
Expand All @@ -85,14 +85,14 @@ public static List<FtpFile> BookmarkedFiles()
/// </summary>
public static void ClearBookmarks()
{
Program.log.Info("Clearing all bookmarks");
Program.Log.Info("Clearing all bookmarks");

var filesBookmarks = new List<FtpFile>();
if (File.Exists(LocalExtensions.PathBookmarks))
using (StreamWriter stream = File.CreateText(LocalExtensions.PathBookmarks))
stream.Flush();

Program.log.Info("Bookmarks cleared successfully");
Program.Log.Info("Bookmarks cleared successfully");
}
}
}
42 changes: 21 additions & 21 deletions FileMasta/Files/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,68 +14,68 @@ class Database
/// <summary>
/// URLs for database files
/// </summary>
const string dbOpenFiles = "https://www.dropbox.com/s/0dwmqk1pkj2ndkz/ftp-files.json?raw=true";
const string dbOpenServers = "https://raw.githubusercontent.com/HerbL27/FileMasta/master/Public/ftp-servers.txt";
public const string dbTopSearches = "https://www.dropbox.com/s/512qe4ogan92vea/top-searches.txt?raw=true";
const string DbOpenFiles = "https://www.dropbox.com/s/0dwmqk1pkj2ndkz/ftp-files.json?raw=true";
const string DbOpenServers = "https://raw.githubusercontent.com/HerbL27/FileMasta/master/Public/ftp-servers.txt";
public const string DbTopSearches = "https://www.dropbox.com/s/512qe4ogan92vea/top-searches.txt?raw=true";

/// <summary>
/// Database file names
/// </summary>
const string fileNameFiles = "ftp-files.json";
const string fileNameServers = "ftp-servers.txt";
const string FileNameFiles = "ftp-files.json";
const string FileNameServers = "ftp-servers.txt";

/// <summary>
/// Checks if database files exists at users data directory, if so whether they're
/// the same size, and downloads the latest one if either return false
/// </summary>
public static void UpdateLocalDatabase()
{
Program.log.Info("Starting database updates");
Program.Log.Info("Starting database updates");

try
{
if (IsFileOutOfDate(dbOpenFiles, fileNameFiles))
if (IsFileOutOfDate(DbOpenFiles, FileNameFiles))
{
Program.log.Info($"Updating {fileNameFiles}...");
Program.Log.Info($"Updating {FileNameFiles}...");
using (var client = new WebClient())
client.DownloadFile(new Uri(dbOpenFiles), $"{LocalExtensions.PathData}{fileNameFiles}");
Program.log.Info($"{fileNameFiles} updated");
client.DownloadFile(new Uri(DbOpenFiles), $"{LocalExtensions.PathData}{FileNameFiles}");
Program.Log.Info($"{FileNameFiles} updated");
}
}
catch (Exception ex)
{
Program.log.Error($"Failed to update {fileNameFiles}", ex);
Program.Log.Error($"Failed to update {FileNameFiles}", ex);
MessageBox.Show(MainForm.Form, "Unable to update database.\n\n" + ex.Message);
}
finally
{
// Deserializes database first line containing meta info
MainForm.DbMetaData = JsonConvert.DeserializeObject<Metadata>(File.ReadLines($"{LocalExtensions.PathData}{fileNameFiles}").First());
MainForm.DbMetaData = JsonConvert.DeserializeObject<Metadata>(File.ReadLines($"{LocalExtensions.PathData}{FileNameFiles}").First());

// Store files in the main form, skipping the first line as it contains the db metadata
foreach (var item in File.ReadAllLines($"{LocalExtensions.PathData}{fileNameFiles}").Skip(1))
foreach (var item in File.ReadLines($"{LocalExtensions.PathData}{FileNameFiles}").Skip(1))
if (StringExtensions.IsValidJSON(item))
MainForm.DbOpenFiles.Add(JsonConvert.DeserializeObject<FtpFile>(item));
}

try
{
if (IsFileOutOfDate(dbOpenServers, fileNameServers))
if (IsFileOutOfDate(DbOpenServers, FileNameServers))
{
Program.log.Info($"Updating {fileNameServers}...");
Program.Log.Info($"Updating {FileNameServers}...");
using (var client = new WebClient())
client.DownloadFile(new Uri(dbOpenServers), $"{LocalExtensions.PathData}{fileNameServers}");
Program.log.Info($"{fileNameServers} updated");
client.DownloadFile(new Uri(DbOpenServers), $"{LocalExtensions.PathData}{FileNameServers}");
Program.Log.Info($"{FileNameServers} updated");
}
}
catch (Exception ex)
{
Program.log.Error($"UPDATE FAILED {fileNameServers}", ex);
Program.Log.Error($"UPDATE FAILED {FileNameServers}", ex);
MessageBox.Show(MainForm.Form, "Unable to update database.\n\n" + ex.Message);
}
finally
{
MainForm.DbOpenServers.AddRange(File.ReadAllLines($"{LocalExtensions.PathData}{fileNameServers}"));
MainForm.DbOpenServers.AddRange(File.ReadLines($"{LocalExtensions.PathData}{FileNameServers}"));
}
}

Expand All @@ -89,7 +89,7 @@ public static bool IsFileOutOfDate(string webFile, string fileName)
{
try
{
Program.log.Info($"Checking if '{fileName}' needs to be updated");
Program.Log.Info($"Checking if '{fileName}' needs to be updated");

if (File.Exists($"{LocalExtensions.PathData}{fileName}"))
if (WebExtensions.WebFileSize($"{webFile}") == new FileInfo($"{LocalExtensions.PathData}{fileName}").Length)
Expand All @@ -99,7 +99,7 @@ public static bool IsFileOutOfDate(string webFile, string fileName)
else
return true;
}
catch (Exception ex) { Program.log.Error($"Unable to check '{fileName}' for update, URL : {webFile}", ex); return true; }
catch (Exception ex) { Program.Log.Error($"Unable to check '{fileName}' for update, URL : {webFile}", ex); return true; }
}

/// <summary>
Expand Down
45 changes: 20 additions & 25 deletions FileMasta/Files/Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using FileMasta.Extensions;
using FileMasta.Models;

Expand All @@ -25,42 +23,39 @@ public enum Sort { Name, Size, Date }
/// <param name="type">Filter by type</param>
/// <param name="host">Filter by FTP host</param>
/// <returns>Returns list of files matching selected preferences</returns>
static readonly object LoadSearchListLock = new object();
static readonly object SearchLock = new object();
public static List<FtpFile> Search(List<FtpFile> dataFiles, string phrase, Sort sort, string[] type, string host)
{
lock (LoadSearchListLock)
lock (SearchLock)
{
bool reverseSort = sort == MainForm.Form.SelectedFilesSort;
SortFiles(dataFiles, sort, reverseSort);

return dataFiles.Select(item =>
new
{
i = item,
Props = item.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public)
})
.Where(item => item.Props.Any(p =>
{
var val = p.GetValue(item.i, null);
return val != null
&& (p.Name == "URL" || string.IsNullOrEmpty("URL"))
&& HasFileExtension(type, val.ToString())
&& HasFileHost(host, val.ToString())
&& StringExtensions.ContainsAll(Uri.UnescapeDataString(val.ToString()), StringExtensions.GetWords(phrase.ToLower()));
}))
.Select(item => item.i)
.ToList();
SortFiles(dataFiles, sort, sort == MainForm.Form.SelectedFilesSort);
return dataFiles.Where(x =>
HasFileType(type, x.URL) &&
HasFileHost(host, x.URL) &&
StringExtensions.ContainsAll(Uri.UnescapeDataString(x.URL), StringExtensions.GetWords(phrase.ToLower()))).ToList();
}
}

public static bool HasFileExtension(string[] type, string fileUrl)
/// <summary>
/// Returns bool to determine if file URL contains file type
/// </summary>
/// <param name="type">Filetypes to check for</param>
/// <param name="fileUrl">File URL</param>
/// <returns>Returns true if is filetype</returns>
public static bool HasFileType(string[] type, string fileUrl)
{
if (type == Types.Everything)
return true;
else
return type.Any(x => Path.GetExtension(fileUrl).Replace(".", "").ToLower().Contains(x.ToLower()));
}

/// <summary>
/// Returns bool to determine if file URL has file host
/// </summary>
/// <param name="host">Host to check for</param>
/// <param name="fileUrl">File URL</param>
/// <returns></returns>
public static bool HasFileHost(string host, string fileUrl)
{
if (host == "")
Expand Down

0 comments on commit 44c4f9d

Please sign in to comment.