Jump to content
Ketarin forum

Truncate Version Number


OLLI_S
 Share

Recommended Posts

Hello,

 

I read the "How-To" and I also understood it.

 

In the "How-To" there is also a description how to add Firefox.

This is a great example to show the problem I have.

The Firefox installer file is Firefox Setup 3.0.1.exe.

The text on the Mozilla download page is 3.0.1.

So here you can store the version number displayed at the web page and then use this number to have a dynamic download file.

 

At the application CCleaner (http://www.piriform.com/ccleaner/download) I have the following data:

The version number displayed at the download page is 2.34.1200

The installer file you download has the following file name: csetup234.exe

So taking the original version number is not working here.

 

Is there a way to take only parts of the version number?

So I would only take the red colored digits in the version number: 2.34.1200

 

I know that for CCleaner there is a download link at filehippo.

But this is a general problem that I have very often in applications.

 

Greetings

 

OLLI

Edited by OLLI_S
Link to comment
Share on other sites

In these situations, I usually use Split. First capture the "version" as the number above (2.34.1200), then generate the download filename using:

csetup{version:split:0:.}{version:split:1:.}.exe

 

This method will work fine UNTIL they change the download filenames to use a different pattern - and they will inevitably do that eventually.

Link to comment
Share on other sites

Why not just get the Version from the download page -- http://www.piriform.com/ccleaner/download/standard/ using 'setTimeout('location.href="http://download.piriform.com/ccsetup' and the start selection and .exe" and the end selection?

 

Ron

 

If i understood correctly that will work too (like the suggestion from shawn), this one is actually closer to one of my favorite solutions but i don't track versions due to the problem shawn refered. I have created 2 XML's, both are somewhat different yet possible aproaches to the same 'problem', import them into your Ketarin window so you can see the differences & use the one that suites you best.

 

<?xml version='1.0' encoding='utf-8'?>
<Jobs>
 <ApplicationJob xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <WebsiteUrl />
   <UserNotes />
   <LastFileSize>0</LastFileSize>
   <LastFileDate xsi:nil="true" />
   <IgnoreFileInformation>false</IgnoreFileInformation>
   <DownloadBeta>Default</DownloadBeta>
   <DownloadDate xsi:nil="true" />
   <CheckForUpdatesOnly>false</CheckForUpdatesOnly>
   <VariableChangeIndicator />
   <CanBeShared>true</CanBeShared>
   <ShareApplication>false</ShareApplication>
   <ExclusiveDownload>false</ExclusiveDownload>
   <HttpReferer />
   <Variables>
     <item>
       <key>
         <string>version</string>
       </key>
       <value>
         <UrlVariable>
           <RegexRightToLeft>false</RegexRightToLeft>
           <VariableType>RegularExpression</VariableType>
           <Regex>Version.+?(\d\.\d+)\.</Regex>
           <Url>http://www.piriform.com/ccleaner/download</Url>
           <Name>version</Name>
         </UrlVariable>
       </value>
     </item>
   </Variables>
   <ExecuteCommand />
   <ExecutePreCommand />
   <Category>Cleanup</Category>
   <SourceType>FixedUrl</SourceType>
   <DeletePreviousFile>true</DeletePreviousFile>
   <Enabled>true</Enabled>
   <FileHippoId />
   <LastUpdated xsi:nil="true" />
   <TargetPath>{root}\</TargetPath>
   <FixedDownloadUrl>http://download.piriform.com/ccsetup{version:replace:.:}.exe</FixedDownloadUrl>
   <Name>CCleaner (1)</Name>
 </ApplicationJob>
</Jobs>

 

<?xml version='1.0' encoding='utf-8'?>
<Jobs>
 <ApplicationJob xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <WebsiteUrl />
   <UserNotes />
   <LastFileSize>0</LastFileSize>
   <LastFileDate xsi:nil="true" />
   <IgnoreFileInformation>false</IgnoreFileInformation>
   <DownloadBeta>Default</DownloadBeta>
   <DownloadDate xsi:nil="true" />
   <CheckForUpdatesOnly>false</CheckForUpdatesOnly>
   <VariableChangeIndicator />
   <CanBeShared>true</CanBeShared>
   <ShareApplication>false</ShareApplication>
   <ExclusiveDownload>false</ExclusiveDownload>
   <HttpReferer />
   <Variables>
     <item>
       <key>
         <string>version</string>
       </key>
       <value>
         <UrlVariable>
           <RegexRightToLeft>false</RegexRightToLeft>
           <VariableType>RegularExpression</VariableType>
           <Regex>Version.+?(\d\.\d+)\.</Regex>
           <Url>http://www.piriform.com/ccleaner/download</Url>
           <Name>version</Name>
         </UrlVariable>
       </value>
     </item>
     <item>
       <key>
         <string>durl</string>
       </key>
       <value>
         <UrlVariable>
           <RegexRightToLeft>false</RegexRightToLeft>
           <VariableType>RegularExpression</VariableType>
           <Regex>href="(http://[^"]+\.exe)"</Regex>
           <Url>http://www.piriform.com/ccleaner/download/standard</Url>
           <Name>durl</Name>
         </UrlVariable>
       </value>
     </item>
   </Variables>
   <ExecuteCommand />
   <ExecutePreCommand />
   <Category>Cleanup</Category>
   <SourceType>FixedUrl</SourceType>
   <PreviousLocation />
   <DeletePreviousFile>true</DeletePreviousFile>
   <Enabled>true</Enabled>
   <FileHippoId />
   <LastUpdated xsi:nil="true" />
   <TargetPath>{root}\</TargetPath>
   <FixedDownloadUrl>{durl}</FixedDownloadUrl>
   <Name>CCleaner (2)</Name>
 </ApplicationJob>
</Jobs>

Edited by josh
Link to comment
Share on other sites

@Josh, I'd like to make a recommendation about your regex patterns:

Version.+?(\d\.\d+)\.

This should really, at a minimum, be:

Version.+?(\d+\.\d+)\.

This will ensure that the moment CCleaner 10.0 is released, your template continues to function. I've seen several templates using similar single-digit or digit-limiting patterns in the past break because of an assumed length in the major, minor or build integers - and it's far more reliable to not rely on a specific length.

 

I personally would have used something like this to get the version:

Version[^<>]+?([\d\.]+)\.

*But* since the filename is dependent upon a version string that's impossible to truly predict (major.minor will NOT work once 3.0 is released!), I would instead find the direct URL on the page and consume that in another variable, passing that into the download field. For this one, I'd use something like (pulled from */ccleaner/standard/):

["'](http\://download\.piriform\.com/[^'"]+\.exe)["'\?&]

 

I use the ["'] and ["'\?&] wrappers because I've experienced a number of times where the site switches between quoting styles, or implements something like Google Analytics with download tracking (see the recent changes on code.google.com for a great example of justification). It's much easier to predict the truly acceptable values than it is to debug and then rewrite the template each time a change is made on the target site.

Link to comment
Share on other sites

I'm not sure if it will. If you create a variable which only contains the major version number and use this one as indicator for changes, you probably can. But you can do that already with regular expressions if necessary.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.