Skip to content

Commit

Permalink
Implement code to look at #147 writing to Stdout (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobya authored May 31, 2021
1 parent de71e97 commit 99cdea2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 8 deletions.
27 changes: 27 additions & 0 deletions src/MainUtils.pas
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ TDocumentConverter = class
FWordConstants : TResourceStrings;

FNetHandle: HINTERNET;
FOutputIsStdOut: Boolean;


procedure SetCompatibilityMode(const Value: Integer);
Expand All @@ -77,6 +78,7 @@ TDocumentConverter = class
procedure SetpdfExportRange(const Value: Integer);
function getWordConstants: TResourceStrings;
procedure LogMainHelp;
procedure SetOutputIsStdOut(const Value: Boolean);


protected
Expand Down Expand Up @@ -150,6 +152,7 @@ TDocumentConverter = class
property InputIsDir : Boolean read FInputIsDir write SetIsDirInput;
property OutputIsFile : Boolean read FOutputIsFile write SetIsFileOutput;
property OutputIsDir : Boolean read FOutputIsDir write SetIsDirOutput;
property OutputIsStdOut : Boolean read FOutputIsStdOut write SetOutputIsStdOut;
property DoSubDirs : Boolean read FDoSubDirs write SetDoSubDirs;
property OutputExt : string read FOutputExt write SetOutputExt;
property LogLevel : integer read FLogLevel write SetLogLevel;
Expand Down Expand Up @@ -492,6 +495,9 @@ function TDocumentConverter.Execute: string;
ErrorMessage, EventMsg : String;
ConversionInfo : TConversionInfo;
StartTime , EndTime : cardinal;
FileStream ,OutStream : TStream;



begin

Expand Down Expand Up @@ -603,6 +609,18 @@ function TDocumentConverter.Execute: string;
// Make a call to webhook if it exists
EventMsg := AfterConversion(FileToConvert, FileToCreate);

// This is experimental. Does not seem to work correctly for anything other than plain text
// files. Any binary info seems to be corrupted. Might be a good project for someone.
if OutputIsStdOut then
begin

FileStream := TFileStream.Create(FileToCreate,fmOpenRead); // This creates the input stream
OutStream := THandleStream.Create(GetStdHandle(STD_OUTPUT_HANDLE)); // Here goes the output stream
OutStream.CopyFrom(FileStream, FileStream.Size); // And the copy operation

end;



end
else // Conversion not successful
Expand Down Expand Up @@ -931,6 +949,10 @@ procedure TDocumentConverter.LoadConfig(Params: TStrings);
end;

end
else if (id = '--STDOUT') then
BEGIN
OutPutIsStdOut := true;
END
else if (id = '-FX') or
(id = '--INPUTFILEEXTENSION') then
begin
Expand Down Expand Up @@ -1527,6 +1549,11 @@ procedure TDocumentConverter.SetOutputFileFormatString(const Value: String);
FOutputFileFormatString := Value;
end;

procedure TDocumentConverter.SetOutputIsStdOut(const Value: Boolean);
begin
FOutputIsStdOut := Value;
end;

procedure TDocumentConverter.SetOutputLog(const Value: Boolean);
begin
FOutputLog := Value;
Expand Down
26 changes: 18 additions & 8 deletions src/docto.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<DCC_DCCCompiler>DCC32</DCC_DCCCompiler>
<ProjectVersion>18.8</ProjectVersion>
<Platform Condition="'$(Platform)'==''">Win32</Platform>
<TargetedPlatforms>1</TargetedPlatforms>
<TargetedPlatforms>3</TargetedPlatforms>
<Platform>Win32</Platform>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Base' or '$(Base)'!=''">
Expand All @@ -35,6 +35,11 @@
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='Win64' and '$(Base)'=='true') or '$(Base_Win64)'!=''">
<Base_Win64>true</Base_Win64>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Release' or '$(Cfg_1)'!=''">
<Cfg_1>true</Cfg_1>
<CfgParent>Base</CfgParent>
Expand Down Expand Up @@ -198,6 +203,13 @@
<iPad_Launch1536x2048>$(BDS)\bin\Artwork\iOS\iPad\FM_LaunchImagePortrait_1536x2048.png</iPad_Launch1536x2048>
<iPad_Launch2048x1536>$(BDS)\bin\Artwork\iOS\iPad\FM_LaunchImageLandscape_2048x1536.png</iPad_Launch2048x1536>
</PropertyGroup>
<PropertyGroup Condition="'$(Base_Win64)'!=''">
<DCC_Namespace>Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;$(DCC_Namespace)</DCC_Namespace>
<BT_BuildType>Debug</BT_BuildType>
<VerInfo_IncludeVerInfo>false</VerInfo_IncludeVerInfo>
<VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
<VerInfo_Locale>1033</VerInfo_Locale>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_1)'!=''">
<DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols>
<DCC_Define>RELEASE;$(DCC_Define)</DCC_Define>
Expand Down Expand Up @@ -231,14 +243,14 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_3_Win32)'!=''">
<VerInfo_MajorVer>1</VerInfo_MajorVer>
<Debugger_RunParams>-wd -f &quot;D:\Development\GitHub\DocTo\test\Inputfiles\Mayonnaise.doc&quot; -o &quot;D:\Development\GitHub\DocTo\test\GeneratedFiles\&quot; -T wdFormatPDF --PDF-FROMPAGE wdExportSelection --PDF-OpenAfterExport</Debugger_RunParams>
<VerInfo_Build>56</VerInfo_Build>
<Debugger_RunParams>-wd -f &quot;D:\Development\GitHub\DocTo\test\Inputfiles\pie3.doc&quot; -o &quot;D:\Development\GitHub\DocTo\test\GeneratedFiles\Pie3.txt&quot; -T wdFormatText --Stdout -Q</Debugger_RunParams>
<VerInfo_Build>57</VerInfo_Build>
<VerInfo_PreRelease>false</VerInfo_PreRelease>
<VerInfo_AutoIncVersion>true</VerInfo_AutoIncVersion>
<VerInfo_AutoGenVersion>false</VerInfo_AutoGenVersion>
<VerInfo_Release>31</VerInfo_Release>
<Icon_MainIcon>docto_Icon2.ico</Icon_MainIcon>
<VerInfo_Keys>CompanyName=Toflidium Software;FileDescription=DocTo - Convert doc files to any available format;FileVersion=1.3.31.56;InternalName=;LegalCopyright=Toby Allen;LegalTrademarks=;OriginalFilename=docto.exe;ProductName=DocTo;ProductVersion=1.3;Comments=https://github.com/tobya/DocTo;ProgramID=com.embarcadero.$(MSBuildProjectName)</VerInfo_Keys>
<VerInfo_Keys>CompanyName=Toflidium Software;FileDescription=DocTo - Convert doc files to any available format;FileVersion=1.3.31.57;InternalName=;LegalCopyright=Toby Allen;LegalTrademarks=;OriginalFilename=docto.exe;ProductName=DocTo;ProductVersion=1.3;Comments=https://github.com/tobya/DocTo;ProgramID=com.embarcadero.$(MSBuildProjectName)</VerInfo_Keys>
<DCC_ExeOutput>..\exe</DCC_ExeOutput>
<Manifest_File>$(BDS)\bin\default_app.manifest</Manifest_File>
<AppEnableRuntimeThemes>true</AppEnableRuntimeThemes>
Expand Down Expand Up @@ -344,18 +356,15 @@
<Platform value="iOSDevice32">False</Platform>
<Platform value="iOSDevice64">False</Platform>
<Platform value="iOSSimulator">False</Platform>
<Platform value="Linux64">False</Platform>
<Platform value="OSX32">False</Platform>
<Platform value="Win32">True</Platform>
<Platform value="Win64">False</Platform>
<Platform value="Win64">True</Platform>
</Platforms>
<Deployment Version="3">
<DeployFile LocalName="$(BDS)\Redist\osx32\libcgunwind.1.0.dylib" Class="DependencyModule">
<Platform Name="OSX32">
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="..\exe\docto.rsm" Configuration="TobyBuild" Class="DebugSymbols"/>
<DeployFile LocalName="..\exe\docto.exe" Configuration="TobyBuild" Class="ProjectOutput"/>
<DeployFile LocalName="$(BDS)\Redist\iossimulator\libcgunwind.1.0.dylib" Class="DependencyModule">
<Platform Name="iOSSimulator">
Expand All @@ -367,6 +376,7 @@
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="..\exe\docto.rsm" Configuration="TobyBuild" Class="DebugSymbols"/>
<DeployClass Name="AdditionalDebugSymbols">
<Platform Name="OSX32">
<Operation>1</Operation>
Expand Down
Binary file modified src/docto.res
Binary file not shown.
1 change: 1 addition & 0 deletions test/teststdout.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"../exe/docto.exe" -o "%~d0%~p0GeneratedFiles\Pie3.txt" -T wdFormatText -f "%~d0%~p0Inputfiles\pie3.doc" --stdout -G -Q

0 comments on commit 99cdea2

Please sign in to comment.