Skip to content

Commit ac7d180

Browse files
First public release
1 parent 3b80ad1 commit ac7d180

File tree

12 files changed

+34
-16
lines changed

12 files changed

+34
-16
lines changed

CalibreImport/CalibreImport.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ namespace CalibreImport
2525
[DisplayName("CalibreImport")]
2626
[COMServerAssociation(AssociationType.AllFiles)] //needed for Directory Opus, apparently.
2727
[COMServerAssociation(AssociationType.ClassOfExtension, ".epub", ".pdf", ".mobi", ".azw", ".azw3", ".fb2", ".djvu", ".lrf", ".rtf", ".txt", ".doc", ".docx", ".odt", ".htm", ".html", ".cbz", ".cbr", ".pdb", ".snb", ".tcr", ".zip", ".rar")]
28+
29+
// Welcome to CalibreImport, the main class of this Shell Extension.
30+
// This class is responsible for creating the context menu and handling the calibredb.exe import process.
31+
// It uses the SharpShell library to create a COM server that integrates with Windows Explorer.
32+
// The class is decorated with various attributes to specify its COM visibility and associations with file types.
2833
public class CalibreImport : SharpContextMenu
2934
{
3035
private List<string> _supportedExtensions = new List<string>();
@@ -203,10 +208,11 @@ protected override ContextMenuStrip CreateMenu()
203208
}
204209

205210
// Define a non-generic delegate type
211+
// whatever that means
206212
public delegate void ReportProgressDelegate(int progress);
207213

208214
// Primary import handler that processes single or multiple files
209-
// Manages Calibre process state and handles user interaction during import
215+
// Manages Calibre process state, and handles user interaction during import
210216
private void ExecuteImport(string selectedLibrary = null, ReportProgressDelegate reportProgress = null)
211217
{
212218
try
@@ -551,7 +557,7 @@ private void LoadSupportedExtensions()
551557
};
552558
}
553559

554-
// Get list of supported file extensions
560+
// Get the list of supported eBook file extensions
555561
private static List<string> GetFileExtensions()
556562
{
557563
var extensions = new List<string>();
@@ -610,7 +616,7 @@ private void KillCalibre()
610616
}
611617
}
612618

613-
// Get list of Calibre libraries from gui.json
619+
// Call on the CalibreLibraryManager class to retrieve the list of Calibre libraries
614620
private List<CalibreLibrary> GetCalibreLibraries()
615621
{
616622
return CalibreLibraryManager.GetLibraries();

CalibreImport/CalibreImport.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@
112112
C# files being compiled
113113
-->
114114
<ItemGroup>
115-
<Compile Include="AppSettings.cs" />
116115
<Compile Include="AutomergeOption.cs" />
117116
<Compile Include="CalibreImport.cs" />
118117
<Compile Include="CalibreLibraryManager.cs" />
@@ -126,7 +125,6 @@
126125
</Compile>
127126
<Compile Include="Locales.cs" />
128127
<Compile Include="Logger.cs" />
129-
<Compile Include="Program.cs" />
130128
<Compile Include="ProgressForm.cs">
131129
<SubType>Form</SubType>
132130
</Compile>

CalibreImport/CalibreLibraryManager.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,24 @@ namespace CalibreImport
88
{
99
public static class CalibreLibraryManager
1010
{
11-
/// <summary>
12-
/// Retrieves the list of Calibre libraries from gui.json.
13-
/// </summary>
14-
/// <param name="logger">
15-
/// Optional logger action to write log messages (e.g., (message, color) => Logger.LogThis(message, color)).
16-
/// </param>
17-
/// <returns>List of CalibreLibrary objects or null on error.</returns>
11+
// This method retrieves the list of Calibre libraries from the "gui.json" file.
12+
// It parses it, and extracts the library paths and names.
13+
// If anyone knows a more appropriate source for the list of libraries, let me know.
1814
public static List<CalibreLibrary> GetLibraries()
1915
{
2016
try
2117
{
2218
var calibreConfigPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "calibre");
2319
var guiFilePath = Path.Combine(calibreConfigPath, "gui.json");
2420

21+
// Can't do much with this app if the list of libraries can't be found.
2522
if (!File.Exists(guiFilePath))
2623
{
2724
Logger.LogThis($"Calibre gui.json not found at {guiFilePath}. Cannot extract list of Libraries.");
2825
return null;
2926
}
3027

28+
// Read the JSON file and parse it
3129
var guiJson = JObject.Parse(File.ReadAllText(guiFilePath));
3230
var libraries = guiJson["library_usage_stats"]?
3331
.ToObject<Dictionary<string, object>>()?.Keys

CalibreImport/CheckPortable.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ namespace CalibreImport
66
{
77
public static class CheckPortable
88
{
9+
// Check if the application is running in portable mode
10+
// It is not really "portable", though, as registry entries are still needed.
11+
// It just checks if the config file is in the same directory as the assembly.
912
public static bool IsPortable()
1013
{
1114
string assemblyName = Assembly.GetExecutingAssembly().GetName().Name;

CalibreImport/CustomSettings.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ static CustomSettings()
1919
string ConfigName = $"{assemblyName}.config";
2020
string ConfDirectory;
2121

22+
// Check if the application is running in a portable mode
2223
if (CheckPortable.IsPortable())
2324
{
2425
ConfDirectory = Path.GetDirectoryName(typeof(CustomSettings).Assembly.Location);
@@ -28,14 +29,15 @@ static CustomSettings()
2829
ConfDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), assemblyName);
2930
}
3031

31-
// Ensure the directory exists
32+
// Ensure the directory exists, if not create it
3233
if (!Directory.Exists(ConfDirectory))
3334
{
3435
Directory.CreateDirectory(ConfDirectory);
3536
}
3637

3738
string configFilePath = Path.Combine(ConfDirectory, ConfigName);
3839

40+
// Check if the config file exists, if not create a default one
3941
if (!File.Exists(configFilePath))
4042
{
4143
CreateDefaultConfig(configFilePath);
@@ -49,6 +51,7 @@ static CustomSettings()
4951

5052
public static void Save()
5153
{
54+
// Save the configuration settings
5255
config.Save(ConfigurationSaveMode.Modified);
5356
ConfigurationManager.RefreshSection(config.AppSettings.SectionInformation.Name);
5457
}

CalibreImport/InnoSetup/CalibreImportSetup.iss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
[Setup]
99
; Application metadata
1010
AppName={#AppName}
11-
AppVersion=0.0.7.6
11+
AppVersion=0.0.7.7
1212
DefaultDirName={autopf}\{#AppName}
1313
DefaultGroupName={#AppName}
1414
UninstallDisplayIcon={app}\{#MainDll}

CalibreImport/Locales.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
public static class Locales
66
{
77
// ResourceStrings.cs will pick up localization strings from here
8+
// This is a dictionary of dictionaries, where the outer dictionary's key is the culture name.
9+
// In case you were wondering, we adopted this self-made method over the built-in Resources.resx
10+
// method, in order to avoid the need to create a separate file for each language and, more
11+
// importantly, to avoid the creation of locale folders for each language within the release build.
812
private static readonly Dictionary<string, Dictionary<string, string>> _localizedStrings = new Dictionary<string, Dictionary<string, string>>
913
{
1014
{

CalibreImport/Logger.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace CalibreImport
88
{
9+
// This class provide a simple logging mechanism for the application.
910
public static class Logger
1011
{
1112
private static readonly string assemblyName;
@@ -54,6 +55,9 @@ static Logger()
5455
}
5556
}
5657

58+
// This method logs messages to the log file.
59+
// It can log both verbose and non-verbose messages based on the settings.
60+
// The method also enriches the log message with debug information if verbose logging is enabled.
5761
public static void LogThis(string message, bool isVerbose = false)
5862
{
5963
try

CalibreImport/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@
2828
// Build Number
2929
// Revision
3030
//
31-
[assembly: AssemblyVersion("0.0.7.6")]
32-
[assembly: AssemblyFileVersion("0.0.7.6")]
31+
[assembly: AssemblyVersion("0.0.7.7")]
32+
[assembly: AssemblyFileVersion("0.0.7.7")]
-1.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)