You are here

PAM Updates Code: Well, a start anyway

13 posts / 0 new
Last post
Ryan McCue
Ryan McCue's picture
Offline
Last seen: 14 years 6 months ago
Joined: 2006-01-06 21:27
PAM Updates Code: Well, a start anyway

I've got the start of the updates code for the PAM ready. It's still a long way from being finished (doesn't even check yet), but at least it's a start. Rather than being a generic solution for many servers, ala AMP, it only handles the PA site, which reduces the complexity.
Et, viola.

procedure TfrmMenu.GetUpdatesINI();
// Download the updates INI from the PortableApps.com server
// Acknowledgement: http://delphi.about.com/od/internetintranet/a/get_file_net.htm for the function
var
	remoteUpdates: TINIFile;
	remoteUpdatesPath: TString;
	localUpdatesPath: TString;
begin
	remoteUpdatesPath := ExtractFileDir(Application.ExeName) + '\Data\remote_updates.ini';
	localUpdatesPath := ExtractFileDir(Application.ExeName) + '\Data\local_updates.ini';
	if GetInetFile('http://external.portableapps.com/updates.ini', remoteUpdatesPath) then
		if FileExists(localUpdatesPath) then
			remoteUpdates:=TINIFile.Create(remoteUpdatesPath);
			// Stuff
			DeleteFile(localUpdatesPath);
			RenameFile(remoteUpdatesPath, localUpdatesPath);
		else
			if Not RenameFile(remoteUpdatesPath, localUpdatesPath) then
				ShowMessage('Unable to rename updates file. Please make sure the Data directory is writable');
	else
		ShowMessage('Unable to download updates file. Please try again in 5 minutes and if the problem persists, report it to the forums');
end;

And of course, add procedure GetUpdatesINI(); with all the rest of the procedure definitions.
I'll add as much more as I can tonight to get it functional.

Ryan McCue
Ryan McCue's picture
Offline
Last seen: 14 years 6 months ago
Joined: 2006-01-06 21:27
.

This is the final bit I can get done, someone (like John) can take over from here.

Famous last words, eh? This is the second third fourth fifth sixth time I've updated this comment. Watch this space.

function TfrmMenu.GetInetFile (const fileURL, FileName: String): boolean;
//Acknoledgement: http://delphi.about.com/od/internetintranet/a/get_file_net.htm for the function
const
	BufferSize = 1024;
var
	hSession, hURL: HInternet;
	Buffer: array[1..BufferSize] of Byte;
	BufferLen: DWORD;
	f: File;
	sAppName: string;
begin
	result := false;
	sAppName := ExtractFileName(Application.ExeName) ;
	hSession := InternetOpen(PChar(sAppName), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0) ;
	try
		hURL := InternetOpenURL(hSession, PChar(fileURL), nil, 0, 0, 0) ;
		try
			AssignFile(f, FileName) ;
			Rewrite(f,1) ;
		repeat
			InternetReadFile(hURL, @Buffer, SizeOf(Buffer), BufferLen) ;
			BlockWrite(f, Buffer, BufferLen)
		until BufferLen = 0;
			CloseFile(f) ;
			result := True;
		finally
			InternetCloseHandle(hURL)
		end
	finally
		InternetCloseHandle(hSession)
	end
end;

// =====================================

procedure TfrmMenu.GetUpdatesINI();
// Download the updates INI from the PortableApps.com server
// Acknowledgements:
// * http://www.devarticles.com/c/a/Delphi-Kylix/Working-with-INI-Files-in-Delphi/2/
// * http://www.delphibasics.co.uk/RTL.asp?Name=TStringList
var
	appList: TINIFile;
	appListPath: TString;
	currentAppInfo: TINIFile;
	currentAppInfoPath: TString;
	allRemoteAppsList: TStringList;
	allLocalAppsList: TStringList;
	allNewAppsList: TStringList;
	response: Integer;
begin
	appListPath := ExtractFileDir(Application.ExeName) + '\Data\remote_updates.ini';
	if GetInetFile('http://external.portableapps.com/app_list.ini', appListPath) then
			appList:=TINIFile.Create(remoteUpdatesPath);
			appList.ReadSections(allRemoteAppsList);
			// For loops goes here to compare each section with the next
			// Something like this:
			allNewAppsList := TStringList.Create;
			for appCount := 0 to appList.Count-1 do
				appName := allRemoteAppsList[appCount];
				currentAppInfoPath := ExtractFileDir(ExtractFileDir(Application.ExeName)) + '\' + appName + '\App\AppInfo\appinfo.ini';
				if FileExists(currentAppInfoPath) then
					currentAppInfo := TINIFile.Create(currentAppInfoPath);
					if appList.ReadString(appName, 'PackageVersion', '1.0') > currentAppInfo.ReadString('Version', 'PackageVersion', '1.0') then
						response := MessageDlg('New update for ' + appName + 'available. Download?', mtWarning, mbYesNo, 0);
						//Handle response here, should be relatively easy
					end;
				end;
			end;
			DeleteFile(localUpdatesPath);
			RenameFile(remoteUpdatesPath, localUpdatesPath);
	else
		ShowMessage('Unable to download updates file. Please try again in 5 minutes and if the problem persists, report it to the forums');
end;

// =====================================

procedure TfrmMenu.GetAvailableApps();
// Download the updates INI from the PortableApps.com server
// Acknowledgements:
// * http://www.devarticles.com/c/a/Delphi-Kylix/Working-with-INI-Files-in-Delphi/2/
// * http://www.delphibasics.co.uk/RTL.asp?Name=TStringList
var
	remoteUpdates: TINIFile;
	remoteUpdatesPath: TString;
	localUpdates: TINIFile;
	localUpdatesPath: TString;
	allRemoteAppsList: TStringList;
	allLocalAppsList: TStringList;
	allNewAppsList: TStringList;
begin
	remoteUpdatesPath := ExtractFileDir(Application.ExeName) + '\Data\remote_updates.ini';
	localUpdatesPath := ExtractFileDir(Application.ExeName) + '\Data\local_updates.ini';
	if GetInetFile('http://external.portableapps.com/updates.ini', remoteUpdatesPath) then
		if FileExists(localUpdatesPath) then
			remoteUpdates:=TINIFile.Create(remoteUpdatesPath);
			remoteUpdates.ReadSections(allRemoteAppsList);
			localUpdates:=TINIFile.Create(localUpdatesPath);
			localUpdates.ReadSections(allLocalAppsList);
			// For loops goes here to compare each section with the next
			// Something like this:
			allNewAppsList := TStringList.Create;
			for appCount := 0 to allRemoteAppsList.Count-1 do
				appName := allRemoteAppsList[appCount];
				if not FileExists(ExtractFileDir(ExtractFileDir(Application.ExeName)) + '\' + appName + '\App\AppInfo\appinfo.ini') then
					allNewAppsList.Append(remoteUpdates.ReadString(appName, 'DisplayName'));
				end;
			end;
			DeleteFile(localUpdatesPath);
			RenameFile(remoteUpdatesPath, localUpdatesPath);
		else
			if Not RenameFile(remoteUpdatesPath, localUpdatesPath) then
				ShowMessage('Unable to rename updates file. Please make sure the Data directory is writable');
	else
		ShowMessage('Unable to download updates file. Please try again in 5 minutes and if the problem persists, report it to the forums');
end;

Note: I haven't compiled this, so I've got no idea if it works, but it should Smile
Note 2: You'll also need GetInetFile for downloading part.

Edit 5: Well, the previous code only worked out if the server's version had been updated, which is useless. Updated with the proper code and now has a corresponding "getAvailableApps" which retrieves all the apps which the user doesn't have.
Edit 6: GetInetFile function now included
----
Ryan McCue.
Blog.
So all that Airbus-delay trouble over here in Europe is because of YOU!
Simeon.

"If you're not part of the solution, you're part of the precipitate."

Ryan McCue
Ryan McCue's picture
Offline
Last seen: 14 years 6 months ago
Joined: 2006-01-06 21:27
So...

Anyone care to comment? Maybe read this John? Blum
----
Ryan McCue.
Blog.
So all that Airbus-delay trouble over here in Europe is because of YOU!
Simeon.

"If you're not part of the solution, you're part of the precipitate."

wsm23
Offline
Last seen: 12 years 2 months ago
Joined: 2006-01-09 22:05
Bump?

Was that a bump?

Tsk, tsk. Mr McCue.

--
Life is about the journey not the destination!

My site * My Blog

The Kazoo Spartan

Life is about the journey not the destination!

The Kazoo Spartan

Ryan McCue
Ryan McCue's picture
Offline
Last seen: 14 years 6 months ago
Joined: 2006-01-06 21:27
Sssh

Worked though, didn't it Wink
----
Ryan McCue.
Blog.
So all that Airbus-delay trouble over here in Europe is because of YOU!
Simeon.

"If you're not part of the solution, you're part of the precipitate."

Espreon
Espreon's picture
Offline
Last seen: 11 years 8 months ago
Joined: 2006-09-29 18:23
Hey Ryan, finally you make peeps aware

But could you make it so it can handle other sites?

--
As all of ya should know Micro$oft is the Evil Empire, and Windows (a.k.a. Winblows or Windoze) is their greatest general, so please make a difference and install Linux or FreeBSD on yer Windows comp.

Ryan McCue
Ryan McCue's picture
Offline
Last seen: 14 years 6 months ago
Joined: 2006-01-06 21:27
Nope.

It will add about 20 lines of complexity. It is the PortableApps Menu, so the path is hard-coded.

Also, the (suggested) INI format:

[FirefoxPortable]
DisplayName=Mozilla Firefox, Portable Edition
Version=1.0
Description=The award winning web browser on your drive
DownloadUrl=http://downloads.sourceforge.net/portableapps/FirefoxPortable-2.0.0.7.paf.exe
DownloadType=PAF

If you use the download code from that site on the above URL, it will download the actual app, not the HTML page.
----
Ryan McCue.
Blog.
So all that Airbus-delay trouble over here in Europe is because of YOU!
Simeon.

"If you're not part of the solution, you're part of the precipitate."

Espreon
Espreon's picture
Offline
Last seen: 11 years 8 months ago
Joined: 2006-09-29 18:23
Just curious...

How hard will it be to implement compatibility with other sites? Cause I would like to modify the source code, to fit it to my tastes.

--
As all of ya should know Micro$oft is the Evil Empire, and Windows (a.k.a. Winblows or Windoze) is their greatest general, so please make a difference and install Linux or FreeBSD on yer Windows comp.

Ryan McCue
Ryan McCue's picture
Offline
Last seen: 14 years 6 months ago
Joined: 2006-01-06 21:27
Well...

You'd have to adapt it from the files at http://am-portable.svn.sourceforge.net/
----
Ryan McCue.
Blog.
So all that Airbus-delay trouble over here in Europe is because of YOU!
Simeon.

"If you're not part of the solution, you're part of the precipitate."

José Pedro Arvela
Offline
Last seen: 5 years 3 months ago
Joined: 2007-07-10 07:29
Is that based?...

Is that based in my repositories idea?

You know I had an idea for some repositories with a similar kind of files to allow direct download.

You stole that from me!!! *cries at the same time it is happy for his idea being used*
(I know that the repositories were already an idea before I posted my idea)
 
____________________
The Blogger of Portimão or O Blogger de Portimão. Free your mind...

Blue is everything.

Zach Thibeau
Zach Thibeau's picture
Offline
Last seen: 1 year 6 months ago
Developer
Joined: 2006-05-26 12:08
Err....

Actually this was in production for some time but lack of work the project was pretty dead and Ryan is trying to bring it up again Smile
-----------------------------
"I don't fear Computers. I fear the lack of them" Isaac Asimov
My Personal Blog in the making at a new address thibeaz.com Biggrin

your friendly neighbourhood moderator Zach Thibeau

Ryan McCue
Ryan McCue's picture
Offline
Last seen: 14 years 6 months ago
Joined: 2006-01-06 21:27
Yeh, but

This time officially Blum
----
Ryan McCue.
Blog.
So all that Airbus-delay trouble over here in Europe is because of YOU!
Simeon.

"If you're not part of the solution, you're part of the precipitate."

Ryan McCue
Ryan McCue's picture
Offline
Last seen: 14 years 6 months ago
Joined: 2006-01-06 21:27
Updated

Updated, now should look like this:

[PidginPortable]
DisplayName=Pidgin Portable
Description=Pidgin Portable is a versatile instant messaging client that works with AOL, MSN, Yahoo, Google Talk and other systems.
InstallSize=9.3
PackageVersion=2.1.1.0
PackageRevision=0
DisplayVersion=2.1.1

This more closely mirrors the AppInfo.inis
----
Ryan McCue.
Blog.
So all that Airbus-delay trouble over here in Europe is because of YOU!
Simeon.

"If you're not part of the solution, you're part of the precipitate."

Log in or register to post comments