diff --git a/common/windows/delphi/visualkeyboard/VisualKeyboardExportHTML.pas b/common/windows/delphi/visualkeyboard/VisualKeyboardExportHTML.pas index 747dd0aca5d..614f3df8d3d 100644 --- a/common/windows/delphi/visualkeyboard/VisualKeyboardExportHTML.pas +++ b/common/windows/delphi/visualkeyboard/VisualKeyboardExportHTML.pas @@ -1,18 +1,18 @@ (* Name: VisualKeyboardExportHTML Copyright: Copyright (C) SIL International. - Documentation: - Description: + Documentation: + Description: Create Date: 20 Jun 2006 Modified Date: 8 Jun 2012 Authors: mcdurdin - Related Files: - Dependencies: + Related Files: + Dependencies: - Bugs: - Todo: - Notes: + Bugs: + Todo: + Notes: History: 20 Jun 2006 - mcdurdin - Initial version 23 Aug 2006 - mcdurdin - Initial refactor for new visual keyboard 04 Dec 2006 - mcdurdin - Support new XML+XSLT OSK export @@ -50,7 +50,8 @@ implementation Controls, DebugPaths, Dialogs, - ErrorControlledRegistry, + ErrorControlledRegistry, + KeymanPaths, RegistryKeys, Unicode, utildir, @@ -63,15 +64,30 @@ implementation { TVisualKeyboardExportHTML } function GetOSKXSLPath: string; +var + keyman_root: string; begin - with TRegistryErrorControlled.Create do // I2890 - try - RootKey := HKEY_LOCAL_MACHINE; - if OpenKeyReadOnly(SRegKey_KeymanEngine_LM) and ValueExists(SRegValue_RootPath) - then Result := IncludeTrailingPathDelimiter(ReadString(SRegValue_RootPath)) + 'xml\osk\' - else Result := ExtractFilePath(ParamStr(0)) + 'xml\osk\'; - finally - Free; + Result := ExtractFilePath(ParamStr(0)) + 'xml\osk\'; + if not DirectoryExists(Result) then + begin + if TKeymanPaths.RunningFromSource(keyman_root) then + begin + Result := keyman_root + 'windows\src\engine\xml\osk\'; + end + else + begin + with TRegistryErrorControlled.Create do // I2890 + try + RootKey := HKEY_LOCAL_MACHINE; + if OpenKeyReadOnly(SRegKey_KeymanEngine_LM) and ValueExists(SRegValue_RootPath) then + Result := IncludeTrailingPathDelimiter(ReadString(SRegValue_RootPath)) + 'xml\osk\'; + finally + Free; + end; + + if not DirectoryExists(Result) then + Result := ''; + end; end; Result := GetDebugPath('Debug_OSKXSLPath', Result, True); end; @@ -131,100 +147,117 @@ procedure TVisualKeyboardExportHTML.ExportToFile(FileName: WideString); { Structure for HTML keyboard: file + subdirectory with images; always output as UTF-8? } stemp := ChangeFileExt(FileName, '') + '.xml'; - - with TVisualKeyboardExportXML.Create(FKbd) do try - ExportToFile(stemp); - finally - Free; - end; - files := TStringList.Create; - try - doc := CreateDOMDocument; + with TVisualKeyboardExportXML.Create(FKbd) do try - doc.async := False; - doc.validateOnParse := False; - doc.load(stemp); - xsldoc := ComsFreeThreadedDOMDocument.Create; + ExportToFile(stemp); + finally + Free; + end; + + files := TStringList.Create; + try + doc := CreateDOMDocument; try - xsldoc.async := False; - xsldoc.resolveExternals := True; - xsldoc.validateOnParse := False; - xsldoc.load(GetOSKXSLPath + 'osk.xsl'); + doc.async := False; + doc.validateOnParse := False; + if not doc.load(stemp) then + begin + if doc.parseError <> nil then + begin + ShowMessage('Could not load XML: '+doc.parseError.reason); + Exit; + end; + end; + xsldoc := ComsFreeThreadedDOMDocument.Create; + try + xsldoc.async := False; + xsldoc.resolveExternals := True; + xsldoc.validateOnParse := False; + if not xsldoc.load(GetOSKXSLPath + 'osk.xsl') then + begin + if xsldoc.parseError <> nil then + begin + ShowMessage('Could not load transform '+GetOSKXSLPath + 'osk.xsl: '+xsldoc.parseError.reason); + Exit; + end; + end; - xsldoc.setProperty('SelectionNamespaces', 'xmlns:oskexportdetails=''http://www.tavultesoft.com/xml/oskexportdetails'''); - xsldoc.setProperty('SelectionLanguage', 'XPath'); + xsldoc.setProperty('SelectionNamespaces', 'xmlns:oskexportdetails=''http://www.tavultesoft.com/xml/oskexportdetails'''); + xsldoc.setProperty('SelectionLanguage', 'XPath'); - nodes := xsldoc.documentElement.selectNodes('//oskexportdetails:includefile'); - for i := 0 to nodes.length - 1 do - files.Add(nodes.item[i].text); + nodes := xsldoc.documentElement.selectNodes('//oskexportdetails:includefile'); + for i := 0 to nodes.length - 1 do + files.Add(nodes.item[i].text); - xslt := ComsXSLTemplate.Create; - xslt.stylesheet := xsldoc; + xslt := ComsXSLTemplate.Create; + xslt.stylesheet := xsldoc; - xslproc := xslt.createProcessor; + xslproc := xslt.createProcessor; - xslproc.input := doc; - xslproc.addParameter('graphical', FGraphical, ''); - xslproc.addParameter('folders', FFolders, ''); + xslproc.input := doc; + xslproc.addParameter('graphical', FGraphical, ''); + xslproc.addParameter('folders', FFolders, ''); - xslproc.transform; - FOutput := xslproc.output; // doc.transformNode(xsldoc); + xslproc.transform; + FOutput := xslproc.output; // doc.transformNode(xsldoc); + finally + xsldoc := nil; + end; finally - xsldoc := nil; + doc := nil; end; - finally - doc := nil; - end; - with TStringList.Create do - try - Text := FOutput; - SaveToFile(FileName, TEncoding.UTF8); // I3337 + with TStringList.Create do + try + Text := FOutput; + SaveToFile(FileName, TEncoding.UTF8); // I3337 + finally + Free; + end; + + if FFolders then + begin + FSubdir := ChangeFileExt(FileName, '')+'_files'; + + if DirectoryExists(FSubdir) and not DirectoryEmpty(FSubdir) then + begin + if MessageDlg('The subdirectory "'+FSubdir+'" already exists. Images for the HTML file will be placed in this '+ + 'subdirectory. If you continue, any files currently in the directory will be deleted.'#13#10#13#10+ + 'Continue exporting and delete all existing files in the subdirectory?', mtConfirmation, mbOkCancel, 0) = mrCancel then Exit; + if not EmptyDirectory(FSubdir) then + if MessageDlg('The subdirectory "'+FSubdir+'" was not able to be emptied. Continue exporting anyway?', + mtConfirmation, mbOkCancel, 0) = mrCancel then Exit; + end; + + CreateDir(FSubdir); + end + else + FSubdir := ExtractFileDir(FileName); + + s := GetOSKXSLPath; + if FGraphical then + for i := 0 to files.Count - 1 do + CopyFile(PChar(s+files[i]), PChar(FSubDir+'\'+files[i]), True); finally - Free; + files.Free; end; - if FFolders then - begin - FSubdir := ChangeFileExt(FileName, '')+'_files'; - - if DirectoryExists(FSubdir) and not DirectoryEmpty(FSubdir) then + s := ChangeFileExt(stemp, '')+'_xml_files\'; + if FGraphical then + if FindFirst(s + '*', 0, f) = 0 then begin - if MessageDlg('The subdirectory "'+FSubdir+'" already exists. Images for the HTML file will be placed in this '+ - 'subdirectory. If you continue, any files currently in the directory will be deleted.'#13#10#13#10+ - 'Continue exporting and delete all existing files in the subdirectory?', mtConfirmation, mbOkCancel, 0) = mrCancel then Exit; - if not EmptyDirectory(FSubdir) then - if MessageDlg('The subdirectory "'+FSubdir+'" was not able to be emptied. Continue exporting anyway?', - mtConfirmation, mbOkCancel, 0) = mrCancel then Exit; + repeat + CopyFile(PChar(s+f.Name), PChar(FSubDir+'\'+f.Name), True); + until FindNext(f) <> 0; + FindClose(f); end; + RecursiveDelete(ExcludeTrailingPathDelimiter(s)); - CreateDir(FSubdir); - end - else - FSubdir := ExtractFileDir(FileName); - - s := GetOSKXSLPath; - if FGraphical then - for i := 0 to files.Count - 1 do - CopyFile(PChar(s+files[i]), PChar(FSubDir+'\'+files[i]), True); finally - files.Free; + DeleteFile(stemp); end; - - s := ChangeFileExt(stemp, '')+'_xml_files\'; - if FGraphical then - if FindFirst(s + '*', 0, f) = 0 then - begin - repeat - CopyFile(PChar(s+f.Name), PChar(FSubDir+'\'+f.Name), True); - until FindNext(f) <> 0; - FindClose(f); - end; - - DeleteFile(stemp); - RecursiveDelete(ExcludeTrailingPathDelimiter(s)); end; end. diff --git a/common/windows/delphi/visualkeyboard/VisualKeyboardExportXML.pas b/common/windows/delphi/visualkeyboard/VisualKeyboardExportXML.pas index 3ef240bc466..9ee294f6cce 100644 --- a/common/windows/delphi/visualkeyboard/VisualKeyboardExportXML.pas +++ b/common/windows/delphi/visualkeyboard/VisualKeyboardExportXML.pas @@ -1,18 +1,18 @@ (* Name: VisualKeyboardExportXML Copyright: Copyright (C) SIL International. - Documentation: - Description: + Documentation: + Description: Create Date: 4 Dec 2006 Modified Date: 26 Jun 2012 Authors: mcdurdin - Related Files: - Dependencies: + Related Files: + Dependencies: - Bugs: - Todo: - Notes: + Bugs: + Todo: + Notes: History: 04 Dec 2006 - mcdurdin - Export to version 7, UTF-8, fix text encoding for key caps 22 Jan 2007 - mcdurdin - Export XML files to filename_xml_files subfolder 19 Mar 2007 - mcdurdin - I699 - Fix crash when exporting OSK to HTML/XML @@ -65,7 +65,6 @@ function TVisualKeyboardExportXML.XMLWideString(FileName: WideString): WideStrin nl: WideString = #13#10; begin s := '' + nl; - s := s + '' + nl; s := s + '' + nl; s := s + '
' + nl; s := s + ' '+SKeymanVersion70+'' + nl; diff --git a/developer/src/.gitignore b/developer/src/.gitignore index 31b79db664b..7ce2ad52302 100644 --- a/developer/src/.gitignore +++ b/developer/src/.gitignore @@ -32,6 +32,7 @@ inst/setup.zip inst/templates.wxs inst/xml.wxs inst/kmc.wxs +tike/xml/osk # /developer/TIKE/ tike/stock.kct diff --git a/developer/src/inst/Makefile b/developer/src/inst/Makefile index ae2e328c821..343fa7063e3 100644 --- a/developer/src/inst/Makefile +++ b/developer/src/inst/Makefile @@ -61,6 +61,7 @@ clean: -del /Q cef.wxs -del /Q templates.wxs -del /Q kmc.wxs + -rd /s /q $(DEVELOPER_ROOT)\src\tike\xml\osk test-releaseexists: cd $(DEVELOPER_ROOT)\src\inst diff --git a/developer/src/inst/download.in.mak b/developer/src/inst/download.in.mak index 54f6940782b..46fa6f6a16b 100644 --- a/developer/src/inst/download.in.mak +++ b/developer/src/inst/download.in.mak @@ -45,9 +45,12 @@ clean-heat: clean-heat-kmc heat-xml: # We copy the files to a temp folder in order to exclude thumbs.db, .vs, etc from harvesting +# We also copy over the OSK files from Keyman Engine (#11199) -rmdir /s/q $(KEYMAN_WIX_TEMP_XML) mkdir $(KEYMAN_WIX_TEMP_XML) + xcopy $(KEYMAN_ROOT)\windows\src\engine\xml\osk $(DEVELOPER_ROOT)\src\tike\xml\osk\ /s /i xcopy $(DEVELOPER_ROOT)\src\tike\xml\* $(KEYMAN_WIX_TEMP_XML)\ /s + -del /f /s /q $(KEYMAN_WIX_TEMP_XML)\Thumbs.db -rmdir /s/q $(KEYMAN_WIX_TEMP_XML)\app\node_modules -for /f %i in ('dir /a:d /s /b $(KEYMAN_WIX_TEMP_XML)\.vs') do rd /s /q %i