Skip to content

Commit

Permalink
Addition of -FX parameter for file type search
Browse files Browse the repository at this point in the history
additional logging added, consolidation of procedure, extra help
  • Loading branch information
tobya committed Mar 18, 2015
1 parent 96503e4 commit b6383c1
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 43 deletions.
108 changes: 72 additions & 36 deletions src/MainUtils.pas
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ TDocumentConverter = class
FIsDirInput: Boolean;
FOutputExt: string;
FWebHook : String;
FExtension : String;
FInputExtension : String;
FCompatibilityMode: Integer;

FHaltOnWordError: Boolean;
Expand Down Expand Up @@ -115,9 +115,11 @@ TDocumentConverter = class
function AvailableFormats() : TStringList; virtual; abstract;
function FormatsExtensions(): TStringList; virtual; abstract;

procedure Log(Msg: String; Level : Integer = ERRORS);
procedure Log(Msg: String; Level : Integer = ERRORS); overload;
procedure Log(Msg: String; List: TStrings; Level: Integer); overload;
procedure LogError(Msg: String);
function CallWebHook(Params: String) : string;
procedure LogHelp(HelpResName : String);

property OutputLog : Boolean read FOutputLog write SetOutputLog;
property OutputLogFile : String read FOutputLogFile write SetOutputLogFile;
Expand All @@ -129,7 +131,7 @@ TDocumentConverter = class
property LogFilename: String read FLogFilename write SetLogFilename;
Property Version : String read FVersionString;
property HaltOnWordError : Boolean read FHaltOnWordError write SetHaltOnWordError;
property Extension: String read GetExtension write SetExtension;
property InputExtension: String read GetExtension write SetExtension;
property CompatibilityMode : Integer read FCompatibilityMode write SetCompatibilityMode;

end;
Expand All @@ -150,11 +152,22 @@ procedure TConsoleLog.Log(Sender: TObject; Log: String);
end;

function TDocumentConverter.CallWebHook(Params: String):string;

var url : string;
begin

try
if FWebHook > '' then
begin
GetURL(FWebHook + '?' + Params);
url := FWebHook + '?' + Params;
GetURL(url);

log(url, verbose);
end;
except on E: Exception do
begin
logerror(E.ClassName + ' ' + E.Message);
end;

end;
end;

Expand Down Expand Up @@ -303,11 +316,11 @@ function TDocumentConverter.Execute: string;


log('Ready to Execute' , VERBOSE);
if FileExists(FileToCreate) then //Not working currently as file doesnt include .ext
(*if FileExists(FileToCreate) then //Not working currently as file doesnt include .ext
begin
raise Exception.Create('FileExists Cannot Create: ' + FileToCreate);
end;
end;*)
try


Expand Down Expand Up @@ -491,24 +504,15 @@ procedure TDocumentConverter.LoadConfig(Params: TStrings);
else if id = '-F' then
begin
FInputFile := value;
// IsFileInput := true;
//If input is Dir rather than file, enumerate files.
if DirectoryExists(FInputFile) then
begin
IsDirInput := true;
DoSubDirs := true;
{TODO: allow user to specify *.doc extension }
ListFiles(finputfile, '*' + Extension,true,FInputFiles);
end
else
begin

IsFileInput := true;
end;


log('Input File is: ' + FInputFile,CHATTY);
end
else if id = '-FX' then
begin
InputExtension := value;
end
else if id = '-L' then
begin
if isNumber(value) then
Expand Down Expand Up @@ -610,24 +614,17 @@ procedure TDocumentConverter.LoadConfig(Params: TStrings);
end
else if (id = '-HJ') then
begin
HelpStrings := TStringList.Create;
try
LoadStringListFromResource('HELPJSON',HelpStrings);
log(HelpStrings.Text);
finally
HelpStrings.Free;
end;
LogHelp('HELPJSON');
halt(2);
end
else if (id = '-HW') then
begin
HelpStrings := TStringList.Create;
try
LoadStringListFromResource('HELPWEBHOOK',HelpStrings);
log(HelpStrings.Text);
finally
HelpStrings.Free;
end;
LogHelp('HELPWEBHOOK');
halt(2);
end
else if (id = '-HX') then
begin
LogHelp('HELPERRORS');
halt(2);
end
else
Expand All @@ -640,6 +637,25 @@ procedure TDocumentConverter.LoadConfig(Params: TStrings);

end;

//Code to run when all parameters have been loaded.
//Get Files

// IsFileInput := true;
//If input is Dir rather than file, enumerate files.
if DirectoryExists(InputFile) then
begin
IsDirInput := true;
DoSubDirs := true;

ListFiles(finputfile, '*' + InputExtension,true,FInputFiles);

log('File List', FInputFiles,verbose);
end
else
begin
IsFileInput := true;
end;



end;
Expand All @@ -663,12 +679,32 @@ procedure TDocumentConverter.Log(Msg: String; Level : Integer = ERRORS );
end;
end;

procedure TDocumentConverter.Log(Msg: String; List: TStrings; Level: Integer);
begin

log(Msg, Level);
log( List.Text, Level);

end;

procedure TDocumentConverter.LogError(Msg: String);
begin
Log('*******************************************', ERRORS);
Log('Error: ' + Msg, ERRORS);
end;

procedure TDocumentConverter.LogHelp(HelpResName: String);
var HelpStrings : TStringList;
begin
HelpStrings := TStringList.Create;
try
LoadStringListFromResource(HelpResName,HelpStrings);
log(HelpStrings.Text);
finally
HelpStrings.Free;
end;
end;

function TDocumentConverter.NewFileNameFromBase(OldBase, NewBase,
FileName, NewExt : String): String;
var
Expand All @@ -694,12 +730,12 @@ procedure TDocumentConverter.SetDoSubDirs(const Value: Boolean);

function TDocumentConverter.GetExtension: String;
begin
Result := fExtension;
Result := fInputExtension;
end;

procedure TDocumentConverter.SetExtension(const Value: String);
begin
FExtension := Value;
FInputExtension := Value;
end;

procedure TDocumentConverter.SetHaltOnWordError(const Value: Boolean);
Expand Down
3 changes: 2 additions & 1 deletion src/docto.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_3_Win32)'!=''">
<Icon_MainIcon>d2icon_QhU_icon.ico</Icon_MainIcon>
<Debugger_RunParams>-L 10 -V</Debugger_RunParams>
<Debugger_RunParams>-f &quot;%~d0%~p0Inputfiles\&quot; -o &quot;%~d0%~p0GeneratedFiles&quot; -T wdFormatPDF -OX pdf -W http://toflidium.com/webhooks/docto/webhook_test.php</Debugger_RunParams>
<VerInfo_MinorVer>7</VerInfo_MinorVer>
<VerInfo_Keys>CompanyName=Toflidium Software;FileDescription=DocTo - Convert doc files to any available format;FileVersion=0.7.2.15;InternalName=;LegalCopyright=Toby Allen;LegalTrademarks=;OriginalFilename=docto.exe;ProductName=DocTo;ProductVersion=0.3.0.0;Comments=</VerInfo_Keys>
<DCC_ExeOutput>..\exe</DCC_ExeOutput>
Expand All @@ -96,6 +96,7 @@
<None Include="res\HelpWebHook.txt"/>
<None Include="res\wdFormatsExt.txt"/>
<None Include="res\WdCompatibilityMode.txt"/>
<None Include="res\HelpErrors.txt"/>
<BuildConfiguration Include="Debug">
<Key>Cfg_2</Key>
<CfgParent>Base</CfgParent>
Expand Down
7 changes: 6 additions & 1 deletion src/docto.dproj.local
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<BorlandProject/>
<BorlandProject>
<Transactions>
<Transaction>2015/03/18 20:38:02.606,=D:\Development\GitHub\DocTo\src\New1.txt</Transaction>
<Transaction>2015/03/18 20:40:32.547,D:\Development\GitHub\DocTo\src\res\HelpErrors.txt=D:\Development\GitHub\DocTo\src\New1.txt</Transaction>
</Transactions>
</BorlandProject>
Binary file modified src/docto.res
Binary file not shown.
12 changes: 12 additions & 0 deletions src/res/HelpErrors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Help Errors

Possible Reasons for Errors.
===========================
ERROR 220

File in Use:
============
When word is trying to saveas, if the file already exists but is in use, eg.
Open or locked you will get this error. Use Verbose logging to see if file
exists before it is written to.

15 changes: 10 additions & 5 deletions src/res/HelpLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Command Line Parameters
Each Parameter should be followed by its value -f "c:\Docs\MyDoc.doc" -O "C:\MyDir\MyFile"
-H This message
-F Input File or Directory
-FX Input Extension to search for if directory. Default ".doc" (will find ".docx" also)
-O Output File or Directory to place converted Docs
-OX Output Extension if -F is Directory.
-T Format(Type) to convert file to, either integer or wdSaveFormat constant.
Expand All @@ -18,7 +19,7 @@ Each Parameter should be followed by its value -f "c:\Docs\MyDoc.doc" -O "C:\My
-L Log Level 1 Errors Only, 2 Standard, 5 CHATTY, 10 VERBOSE
Default: 2 Standard
-C Compatibility Mode. Set to an INTEGER value from https://msdn.microsoft.com/en-us/library/office/ff192388.aspx.
If has a value SaveAs2 will be called. Otherwise SaveAs is called.
-M Ignore all files in __MACOSX\ subdirectory if it exists. Default True.
-G Write Log to file in directory
-GL Log File Name to Use default 'DocTo.Log';
-Q Quiet Mode: Nothing will be output to console. To see any errors you must set -G or -GL
Expand All @@ -41,8 +42,12 @@ ERROR CODES:

COMPATIBILITY MODES:
FROM https://msdn.microsoft.com/en-us/library/office/ff836084.aspx

wdCurrent : 65535 (Compatibility mode equivalent to the latest version of Microsoft Word.)
wdWord2003 : 11 (Word 2010 is put into a mode that is most compatible with Word 2003. Features new to Word 2010 are disabled in this mode.)
wdWord2007 : 12 (Word 2010 is put into a mode that is most compatible with Office Word 2007. Features new to Word 2010are disabled in this mode.)
wdWord2010 : 14 (Word 2013 is put into a mode that is most compatible with . Features new to Word 2013are disabled in this mode.)
wdWord2013 : 15 (Default. All Word 2013 features are enabled.)
wdWord2003 : 11 Word 2010 is put into a mode that is most compatible with Word 2003. Features new to Word 2010 are
disabled in this mode.
wdWord2007 : 12 Word 2010 is put into a mode that is most compatible with Office Word 2007. Features new to Word 2010
are disabled in this mode.
wdWord2010 : 14 Word 2013 is put into a mode that is most compatible with . Features new to Word 2013
are disabled in this mode.
wdWord2013 : 15 Default. All Word 2013 features are enabled.
1 change: 1 addition & 0 deletions src/wdFormats.rc
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ EXTENSIONS TEXT res\wdFormatsExt.txt
HELP TEXT res\HelpLog.txt
HELPJSON TEXT res\HelpJSONLog.txt
HELPWEBHOOK TEXT res\HelpWebHook.txt
HELPERRORS TEXT res\HelpErrors.txt
Binary file modified src/wdFormats.res
Binary file not shown.

0 comments on commit b6383c1

Please sign in to comment.