* Launch Ancestral Sources Update

For users to report plugin bugs and request plugin enhancements; and for authors to test new/new versions of plugins, and to discuss plugin development (in the Programming Technicalities sub-forum). If you want advice on choosing or using a plugin, please ask in General Usage or an appropriate sub-forum.
Post Reply
User avatar
tatewise
Megastar
Posts: 27074
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Launch Ancestral Sources Update

Post by tatewise » 13 Jul 2011 11:29

May I propose the following update to the Launch Ancestral Sources for ... Entry scripts.
This caters for A.S. 64-bit / 32-bit installation in either X:Program Files or X:Program Files(x86), where X: is usually C: drive, but may be different.
It also checks that A.S. Version 2 is installed by testing for a file that only exists in Version 2.
It finally checks that the FH GEDCOM file exists.

Code: Select all


-- Check if file exists
function file_exists(name)
    local f=io.open(name,'r')
    if f~=nil then io.close(f) return true
    else
        return false
    end
end

-- Program Files OS Path
strProgramFiles = os.getenv('PROGRAMFILES')

-- Ancestral Sources executable in Program Files
strASexe = '\Ancestral Sources\Ancestral Sources.exe'

-- Ancestral Sources Version 2 xml in Program Files
strASxml = '\Ancestral Sources\Autotext.xml'

-- Program Files path to A.S. Version 2 xml
strASxmlPath = strProgramFiles..strASxml

if not file_exists(strASxmlPath) then
    -- Alternative Program Files OS Path on 64-bit PC
    strProgramFiles = os.getenv('PROGRAMW6432')
    strASxmlPath = strProgramFiles..strASxml
end

if not file_exists(strASxmlPath) then
     error('Ancestral Sources Version 2 not installed.')
end

strProgram = strProgramFiles..strASexe

if not file_exists(strProgram) then
     error('Ancestral Sources executable not found.')
end

strProjectFile = fhGetContextInfo('CI_GEDCOM_FILE')

if not file_exists(strProjectFile) then
     error('Family Historian GEDCOM file not found.')
end

strType = ' -SOURCE CENSUS'
-- Get Currently Selected Record
tblIndi =  fhGetCurrentRecordSel('INDI')
if #tblIndi > 0 then
     strInd = ' -IND '..fhGetRecordId(tblIndi[1])
else
     strInd = ' '
end
strCmd = 'start '' ''..strProgram..'' -FILE '' .. strProjectFile .. '''..strInd..strType
os.execute(strCmd)
ID:5223
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
Jane
Site Admin
Posts: 8440
Joined: 01 Nov 2002 15:00
Family Historian: V7
Location: Somerset, England
Contact:

Launch Ancestral Sources Update

Post by Jane » 13 Jul 2011 11:56

Code: Select all

if not file_exists(strASxmlPath) then
   -- Alternative Program Files OS Path on 64-bit PC
   strProgramFiles = os.getenv('PROGRAMW6432')
   strASxmlPath = strProgramFiles..strASxml
end 
I think you will need to add a check for nil on strProgramFiles on this or the string concat will fail on a 32 bit system with V1 of AS.

Any reason for the check for the Gedcom file, it comes from FH?
Jane
My Family History : My Photography "Knowledge is knowing that a tomato is a fruit. Wisdom is not putting it in a fruit salad."

User avatar
tatewise
Megastar
Posts: 27074
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Launch Ancestral Sources Update

Post by tatewise » 13 Jul 2011 14:00

Thanks for that advice. I assumed LUA would cope will null strings.
So that string concat code line becomes:

   if strProgramFiles~=nil then strASxmlPath = strProgramFiles..strASxml end


Regarding GEDCOM file, I am simply paranoid about validating things.
Probably comes from spending some years as a system test engineer, and finding too many problems caused by software assumptions not being validated.
It rarely does any harm to double check values, especially those passed from one program to another.

As an example of my paranoia, consider a variable that should only have two values (say 0 and 1).
I would never write:
if var = 0 then
 code for value = 0
else
 code for value = 1
end

I would always test for 0, and test for 1, and report any other value as an error.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
Jane
Site Admin
Posts: 8440
Joined: 01 Nov 2002 15:00
Family Historian: V7
Location: Somerset, England
Contact:

Launch Ancestral Sources Update

Post by Jane » 13 Jul 2011 14:08

The result would be nil which is not the same as an empty string

So if the string = '' that's fine you can concat it, but if os.getenv() does not find a value, the return value is not set to any thing and will equal nil, which can then be tested for.
Jane
My Family History : My Photography "Knowledge is knowing that a tomato is a fruit. Wisdom is not putting it in a fruit salad."

Post Reply