It is currently Fri Jan 18, 2019 10:45 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 25 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: Free macro program to help automate recipe import
PostPosted: Fri Jan 11, 2019 10:41 am 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 4320
Location: Not Sydney!!! (Bad water, no goats)
Marc56us wrote:
Hi Fangbeast,
The tool is still available, but unfortunately they have put their forum in read-only mode. The program is commercial, but not very expensive ($59), well documented and shareware 30 days (test it before).
:wink:


Don't think we will be spending money on anything except what resembles food this year (Spent enough on property repairs!!)

_________________
Amateur Radio, D-STAR/VK3HAF


Top
 Profile  
Reply with quote  
 Post subject: Re: Free macro program to help automate recipe import
PostPosted: Fri Jan 11, 2019 10:42 am 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 4320
Location: Not Sydney!!! (Bad water, no goats)
NicTheQuick wrote:
Qhat about my recipe merge program? Does it work? You did not anser my latest private message.


What private message??? My notifications say 0 messages when I logged in just now.

I also just physically checked and there were no private messages from you in there.

_________________
Amateur Radio, D-STAR/VK3HAF


Top
 Profile  
Reply with quote  
 Post subject: Re: Free macro program to help automate recipe import
PostPosted: Fri Jan 11, 2019 10:45 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jun 22, 2003 7:43 pm
Posts: 323
Location: Germany, Saarbrücken
I sent a message to you with a source code that is capable of merging several recipes. There is a bug in purebasic which prevents a valid XML but it should be possible to make the XML valid again by hand. In your answer you did not say anything about that code. Did you try it?

_________________
Electronics, Crazy & Interesting Stuff, all that with text, image and sound? Click here!

The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.


Top
 Profile  
Reply with quote  
 Post subject: Re: Free macro program to help automate recipe import
PostPosted: Fri Jan 11, 2019 11:12 am 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 4320
Location: Not Sydney!!! (Bad water, no goats)
NicTheQuick wrote:
I sent a message to you with a source code that is capable of merging several recipes. There is a bug in purebasic which prevents a valid XML but it should be possible to make the XML valid again by hand. In your answer you did not say anything about that code. Did you try it?


I haven't received any message about any source code. I'm not that old that I'd forget!! (Even my wife says so)

When did you send it? Last message I had from anyone was on Tuesday, January 8'th from someone (Not you)

_________________
Amateur Radio, D-STAR/VK3HAF


Top
 Profile  
Reply with quote  
 Post subject: Re: Free macro program to help automate recipe import
PostPosted: Fri Jan 11, 2019 11:39 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jun 22, 2003 7:43 pm
Posts: 323
Location: Germany, Saarbrücken
It was December 18th and you answered to it but without reacting to the source code. Here it is:
Quote:
Morning,

I've created the tool to merge the recipe files with Purebasic. But there is a bug in the XML library I try to show to Fred but I was not able to construct an example without using your recipe files. Can I bundle them in a small package and send to Fred so he can take a look why the XMLExport function does its job wrong?

This is my code so far, but the Data.xml file inside the merged recipe file is not valid because there are some characters missing in the end of the file.
Code:
EnableExplicit

UseZipPacker()

Structure Recipe
   file.s
   handle.i
   Map *files()
   content.i
EndStructure

Procedure openRecipe(file.s)
   Protected *recipe.Recipe = AllocateStructure(Recipe)
   Protected filename.s, *buffer, size.i
   
   If Not *recipe
      Debug "Could not allocate memory"
      ProcedureReturn #False
   EndIf

   With *recipe
      \handle = OpenPack(#PB_Any, file, #PB_PackerPlugin_Zip)
      \file = file
     
      If Not \handle
         Debug "Could not open zip"
         Goto error
      EndIf
     
      If Not ExaminePack(\handle)
         Debug "Could not examine zip"
         Goto error
      EndIf
         
      While NextPackEntry(\handle)
         filename = PackEntryName(\handle)
         size = PackEntrySize(\handle, #PB_Packer_UncompressedSize)

         If PackEntryType(\handle) = #PB_Packer_File
            *buffer = 0
            If size > 0
               *buffer = AllocateMemory(size)
               If Not *buffer
                  Debug "Could not allocate memory for " + filename
                  Goto error
               EndIf
               If size <> UncompressPackMemory(\handle, *buffer, size)
                  Debug "Could not unpack file: " + filename
                  Goto error
               EndIf
            EndIf
         Else
            *buffer = -1
         EndIf
         \files(filename) = *buffer
         
         If filename = "Data.xml"
            If size = 0 Or Not *buffer
               Debug filename + " is empty"
               Goto error
            EndIf
            \content = CatchXML(#PB_Any, *buffer, size)
         EndIf
      Wend
   
   EndWith
   
   ProcedureReturn *recipe
   
   error:
   FreeStructure(*recipe)
   If *buffer
      FreeMemory(*buffer)
   EndIf
   
   ProcedureReturn #False
EndProcedure

Procedure getNodeByTag(xmlNode.i)
   
EndProcedure

Procedure mergeRecipes(file.s, List *recipes.Recipe())
   Protected i.i, j.i, *hixz, *node, name.s, *recipesNode, *recipeNode, *sourceImageNode, *recipeImagesNode, *recipeImageNode
   Protected imageCounter.i = 0, oldImage.s, newImage.s
   
   ; Neuen ZIP-Container erstellen
   Protected *mZip = CreatePack(#PB_Any, file, #PB_PackerPlugin_Zip)
   
   ; Create new Data.xml
   Protected *mData = CreateXML(#PB_Any, #PB_UTF8)
   Protected *mHixz = CreateXMLNode(RootXMLNode(*mData), "hixz")
   SetXMLAttribute(*mHixz, "Source", "Merged Cookbook")
   SetXMLAttribute(*mHixz, "FileVersion", "1.0")
   SetXMLAttribute(*mHixz, "date", FormatDate("%yyyy-%mm-%ss", Date()))
   Protected *mCookbooks = CreateXMLNode(*mHixz, "Cookbooks")
   Protected *mCookbookChapters = CreateXMLNode(*mHixz, "CookbookChapters")
   Protected *mRecipes = CreateXMLNode(*mHixz, "Recipes")

   ; Create new Manifest.xml
   Protected *mManifest = CreateXML(#PB_Any, #PB_UTF8)
   Protected *mFdxm = CreateXMLNode(RootXMLNode(*mManifest), "fdxm")
   SetXMLAttribute(*mFdxm, "Source", "Merged Cookbook")
   SetXMLAttribute(*mFdxm, "FileVersion", "1.0")
   SetXMLAttribute(*mFdxm, "date", FormatDate("%yyyy-%mm-%ss", Date()))
   Protected *mFiles = CreateXMLNode(*mFdxm, "Files")
   Protected *mFile
   
   ForEach *recipes()
      With *recipes()
         *recipesNode = XMLNodeFromPath(RootXMLNode(\content), "/hixz/Recipes")
         
         If Not *recipesNode
            Debug \file + ": <recipes> not found."
            Continue
         EndIf
         
         For i = 1 To XMLChildCount(*recipesNode)
            *recipeNode = ChildXMLNode(*recipesNode, i)
           
            *sourceImageNode = XMLNodeFromPath(*recipeNode, "SourceImage")
            If *sourceImageNode
               oldImage = GetXMLAttribute(*sourceImageNode, "FileName")
               newImage = "image" + imageCounter + "." + GetExtensionPart(oldImage)
               imageCounter + 1
               
               If FindMapElement(\files(), "Images/" + oldImage)
                  \files("Images/" + newImage) = \files("Images/" + oldImage)
                  DeleteMapElement(\files(), "Images/" + oldImage)
               EndIf
               
               SetXMLAttribute(*sourceImageNode, "FileName", newImage)
               
               *mFile = CreateXMLNode(*mFiles, "File")
               SetXMLAttribute(*mFile, "FileName", newImage)
               SetXMLAttribute(*mFile, "OriginalFileName", GetXMLAttribute(*sourceImageNode, "OriginalFileName"))
               
               AddPackMemory(*mZip, \files("Images/" + newImage), MemorySize(\files("Images/" + newImage)), "Images/" + newImage)
            EndIf

            *recipeImagesNode = XMLNodeFromPath(*recipeNode, "RecipeImages")
            If *recipeImagesNode
               For j = 1 To XMLChildCount(*recipeImagesNode)
                  *recipeImageNode = ChildXMLNode(*recipeImagesNode, j)
                 
                  oldImage = GetXMLAttribute(*recipeImageNode, "FileName")
                  newImage = "image" + imageCounter + "." + GetExtensionPart(oldImage)
                  imageCounter + 1
                 
                  If FindMapElement(\files(), "Images/" + oldImage)
                     \files("Images/" + newImage) = \files("Images/" + oldImage)
                     DeleteMapElement(\files(), "Images/" + oldImage)
                  EndIf
                 
                  SetXMLAttribute(*recipeImageNode, "FileName", newImage)
                 
                  *mFile = CreateXMLNode(*mFiles, "File")
                  SetXMLAttribute(*mFile, "FileName", newImage)
                  SetXMLAttribute(*mFile, "OriginalFileName", GetXMLAttribute(*recipeImageNode, "OriginalFileName"))
                 
                  AddPackMemory(*mZip, \files("Images/" + newImage), MemorySize(\files("Images/" + newImage)), "Images/" + newImage)
               Next
            EndIf
           
            CopyXMLNode(*recipeNode, *mRecipes)
         Next
      EndWith
   Next
   
   Protected size.i, *buffer
   
   ;FormatXML(*mData, #PB_XML_ReduceSpace | #PB_XML_CutSpace | #PB_XML_ReduceNewline | #PB_XML_CutNewline | #PB_XML_LinuxNewline)
   size = ExportXMLSize(*mData, #PB_XML_NoDeclaration)
   Debug size
   *buffer = AllocateMemory(size)
   If ExportXML(*mData, *buffer, size, #PB_XML_NoDeclaration)
      Debug PeekS(*buffer, size, #PB_UTF8)
      AddPackMemory(*mZip, *buffer, size, "Data.xml")
      FreeMemory(*buffer)
   EndIf
   
   size = ExportXMLSize(*mManifest)
   *buffer = AllocateMemory(size)
   If ExportXML(*mManifest, *buffer, size)
      AddPackMemory(*mZip, *buffer, size, "Manifest.xml")
      FreeMemory(*buffer)
   EndIf

   
   ClosePack(*mZip)
   
EndProcedure

NewList *recipes.Recipe()

; This directory should only contain the fdxz files
Define dir.s = "/home/nicolas/tmp/purebasic/Recipes/"

; This is the new merged recipes file
Define target.s = "/home/nicolas/tmp/purebasic/Recipes/merged.zip"

; First read all recipes into Memory
If ExamineDirectory(0, dir, "*.fdxz")
   While NextDirectoryEntry(0)
      If DirectoryEntryType(0) = #PB_DirectoryEntry_File
         If AddElement(*recipes())
            *recipes() = openRecipe(dir + DirectoryEntryName(0))
         EndIf
      EndIf
   Wend
EndIf

mergeRecipes(target, *recipes())

And this is the related bug report: viewtopic.php?f=23&t=71938

_________________
Electronics, Crazy & Interesting Stuff, all that with text, image and sound? Click here!

The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.


Top
 Profile  
Reply with quote  
 Post subject: Re: Free macro program to help automate recipe import
PostPosted: Fri Jan 11, 2019 12:20 pm 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 4320
Location: Not Sydney!!! (Bad water, no goats)
NicTheQuick, oh dear, I honestly don't remember seeing that in a private message. Wonder how that got past me???

Would have tried it immediately if I had seen it.

Must be ghosts in the PB form (Or as srod would say, goats ate my brain)

But if the characters are invalid, what good is it testing the code? (Honest question). I wouldn't even know how to fix that.

_________________
Amateur Radio, D-STAR/VK3HAF


Top
 Profile  
Reply with quote  
 Post subject: Re: Free macro program to help automate recipe import
PostPosted: Fri Jan 11, 2019 12:46 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jun 22, 2003 7:43 pm
Posts: 323
Location: Germany, Saarbrücken
Maybe I can fix the code with a workaround mentioned in the bug report I linked in my previous post. Unfortunality the bug got not fixed with the latest PB version.

_________________
Electronics, Crazy & Interesting Stuff, all that with text, image and sound? Click here!

The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.


Top
 Profile  
Reply with quote  
 Post subject: Re: Free macro program to help automate recipe import
PostPosted: Sat Jan 12, 2019 2:00 am 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 4320
Location: Not Sydney!!! (Bad water, no goats)
NicTheQuick wrote:
Maybe I can fix the code with a workaround mentioned in the bug report I linked in my previous post. Unfortunality the bug got not fixed with the latest PB version.


Wait a short while. It hit 41 degrees yesterday and we could barely function. We just got back from shopping and it's already 28 and the weather bureau cannot seem to get it right. I need to say away from this hot room.

_________________
Amateur Radio, D-STAR/VK3HAF


Top
 Profile  
Reply with quote  
 Post subject: Re: Free macro program to help automate recipe import
PostPosted: Wed Jan 16, 2019 12:01 pm 
Offline
User
User

Joined: Mon Jul 17, 2017 7:22 am
Posts: 41
Location: Cotswolds England
:o Wow, 10,000 recipes!....I probably may use two or three a week and often one I've used before.
It would take me 600 years to try them all...........are any of them life extending? :D

_________________
If it's falling over......just remember the computer's never wrong


Top
 Profile  
Reply with quote  
 Post subject: Re: Free macro program to help automate recipe import
PostPosted: Wed Jan 16, 2019 11:25 pm 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 4320
Location: Not Sydney!!! (Bad water, no goats)
C87 wrote:
:o Wow, 10,000 recipes!....I probably may use two or three a week and often one I've used before.
It would take me 600 years to try them all...........are any of them life extending? :D


I actually have over 600,000 but 10,000 of those happen to be Living Cookbook fdxz:)

As far as life extending, I have it on good authority that if you cook every one of my 600,000 recipes, you will have gotten your exercise and thus extended your life:):)

_________________
Amateur Radio, D-STAR/VK3HAF


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 25 posts ]  Go to page Previous  1, 2

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye