Commit 0c9b2d28 authored by Rafaël Carré's avatar Rafaël Carré

fix update code in macosx gui

parent 234bf661
{
IBClasses = (
{CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; },
{
ACTIONS = {changeCheckUpdateOnStartup = id; download = id; okay = id; };
CLASS = VLCUpdate;
LANGUAGE = ObjC;
OUTLETS = {
"o_bar_checking" = id;
"o_btn_DownloadNow" = id;
"o_btn_okay" = id;
"o_chk_updateOnStartup" = id;
"o_fld_currentVersionAndSize" = id;
"o_fld_releaseNote" = id;
"o_fld_status" = id;
"o_update_window" = id;
};
SUPERCLASS = NSObject;
}
);
IBVersion = 1;
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IBClasses</key>
<array>
<dict>
<key>CLASS</key>
<string>FirstResponder</string>
<key>LANGUAGE</key>
<string>ObjC</string>
<key>SUPERCLASS</key>
<string>NSObject</string>
</dict>
<dict>
<key>ACTIONS</key>
<dict>
<key>changeCheckUpdateOnStartup</key>
<string>id</string>
<key>download</key>
<string>id</string>
<key>okay</key>
<string>id</string>
</dict>
<key>CLASS</key>
<string>VLCUpdate</string>
<key>LANGUAGE</key>
<string>ObjC</string>
<key>OUTLETS</key>
<dict>
<key>o_bar_checking</key>
<string>id</string>
<key>o_btn_DownloadNow</key>
<string>id</string>
<key>o_btn_okay</key>
<string>id</string>
<key>o_chk_updateOnStartup</key>
<string>id</string>
<key>o_fld_currentVersion</key>
<string>id</string>
<key>o_fld_releaseNote</key>
<string>id</string>
<key>o_fld_status</key>
<string>id</string>
<key>o_update_window</key>
<string>id</string>
</dict>
<key>SUPERCLASS</key>
<string>NSObject</string>
</dict>
</array>
<key>IBVersion</key>
<string>1</string>
</dict>
</plist>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IBDocumentLocation</key>
<string>16 51 356 240 0 0 1280 778 </string>
<key>IBFramework Version</key>
<string>446.1</string>
<string>629</string>
<key>IBOldestOS</key>
<integer>5</integer>
<key>IBOpenObjects</key>
<array>
<integer>5</integer>
</array>
<key>IBSystem Version</key>
<string>8P2137</string>
<string>9C31</string>
<key>targetFramework</key>
<string>IBCocoaFramework</string>
</dict>
</plist>
......@@ -32,6 +32,10 @@
#include <string.h>
#include <vlc_keys.h>
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#import "intf.h"
#import "fspanel.h"
#import "vout.h"
......@@ -420,7 +424,7 @@ static VLCMain *_o_sharedMainInstance = nil;
o_interaction_list = [[VLCInteractionList alloc] init];
o_sfilters = nil;
#ifdef UPDATE_CHECK
//FIXME o_update = [[VLCUpdate alloc] init];
o_update = [[VLCUpdate alloc] init];
#endif
i_lastShownVolume = -1;
......@@ -865,9 +869,8 @@ static VLCMain *_o_sharedMainInstance = nil;
if( !nib_update_loaded )
nib_update_loaded = [NSBundle loadNibNamed:@"Update" owner:self];
// FIXME
//if([o_update shouldCheckForUpdate])
// [NSThread detachNewThreadSelector:@selector(checkForUpdate) toTarget:o_update withObject:NULL];
if([o_update shouldCheckForUpdate])
[NSThread detachNewThreadSelector:@selector(checkForUpdate) toTarget:o_update withObject:NULL];
#endif
/* Handle sleep notification */
......@@ -2019,8 +2022,9 @@ static VLCMain *_o_sharedMainInstance = nil;
#ifdef UPDATE_CHECK
if( !nib_update_loaded )
nib_update_loaded = [NSBundle loadNibNamed:@"Update" owner:self];
[o_update showUpdateWindow];
#else
msg_Err( VLCIntf, "Updates checking was not enabled in this build" );
#endif
}
......
/*****************************************************************************
* update.h: MacOS X Check-For-Update window
*****************************************************************************
* Copyright (C) 2005-2007 the VideoLAN team
* Copyright © 2005-2008 the VideoLAN team
* $Id$
*
* Authors: Felix Kühne <fkuehne@users.sf.net>
* Rafaël Carré <funman@videolanorg>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -21,6 +22,10 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef UPDATE_CHECK
#import <Cocoa/Cocoa.h>
#import <vlc_update.h>
......@@ -30,16 +35,14 @@
IBOutlet id o_btn_DownloadNow;
IBOutlet id o_btn_okay;
IBOutlet id o_fld_releaseNote;
IBOutlet id o_fld_source;
IBOutlet id o_fld_currentVersionAndSize;
IBOutlet id o_fld_currentVersion;
IBOutlet id o_fld_status;
IBOutlet id o_update_window;
IBOutlet id o_bar_checking;
IBOutlet id o_chk_updateOnStartup;
NSString * o_urlOfBinary;
update_t * p_u;
intf_thread_t * p_intf;
vlc_bool_t b_checked;
}
- (IBAction)download:(id)sender;
......@@ -49,8 +52,8 @@
- (BOOL)shouldCheckForUpdate;
- (void)showUpdateWindow;
- (void)initInterface;
- (void)checkForUpdate;
- (void)updateManagement: (vlc_bool_t) b_success;
- (void)performDownload:(NSString *)path;
+ (VLCUpdate *)sharedInstance;
......
/*****************************************************************************
* update.m: MacOS X Check-For-Update window
*****************************************************************************
* Copyright (C) 2005-2007 the VideoLAN team
* Copyright © 2005-2008 the VideoLAN team
* $Id$
*
* Authors: Felix Kühne <fkuehne@users.sf.net>
* Rafaël Carré <funman@videolanorg>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -21,11 +22,9 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/*****************************************************************************
* Note: the code used to communicate with VLC's core was inspired by
* ../wxwidgets/dialogs/updatevlc.cpp, written by Antoine Cellerier.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef UPDATE_CHECK
......@@ -57,39 +56,25 @@ static VLCUpdate *_o_sharedInstance = nil;
[self dealloc];
} else {
_o_sharedInstance = [super init];
}
return _o_sharedInstance;
}
- (void)awakeFromNib
{
/* get up */
p_intf = VLCIntf;
b_checked = VLC_FALSE;
/* clean the interface */
[o_fld_releaseNote setString: @""];
[self initInterface];
}
- (void)dealloc
{
if( o_urlOfBinary )
[o_urlOfBinary release];
[super dealloc];
}
- (void)initInterface
{
[o_fld_currentVersion setString: @""];
/* translate strings to the user's language */
[o_update_window setTitle: _NS("Check for Updates")];
[o_btn_DownloadNow setTitle: _NS("Download now")];
[o_btn_okay setTitle: _NS("OK")];
[o_chk_updateOnStartup setTitle: _NS("Automatically check for updates")];
/* we don't use - (BOOL)shouldCheckUpdateOnStartup because we don't want the Alert
* panel to pop up at this time */
}
return _o_sharedInstance;
}
- (void)awakeFromNib
{
/* we don't use - (BOOL)shouldCheckUpdateOnStartup because we don't want
* the Alert panel to pop up at this time */
[o_chk_updateOnStartup setState: [[NSUserDefaults standardUserDefaults] boolForKey: kPrefUpdateOnStartup]];
}
......@@ -129,17 +114,17 @@ static VLCUpdate *_o_sharedInstance = nil;
- (void)showUpdateWindow
{
/* show the window and check for a potential update */
[o_fld_status setStringValue: _NS("Checking for Updates...")];
[o_fld_currentVersionAndSize setStringValue: @""];
[o_fld_releaseNote setString: @""];
[o_update_window center];
[o_update_window displayIfNeeded];
[o_update_window makeKeyAndOrderFront:nil];
if( !b_checked )
{
[o_bar_checking startAnimation: self];
[self checkForUpdate];
b_checked = VLC_TRUE;
[o_bar_checking stopAnimation: self];
}
}
- (IBAction)download:(id)sender
......@@ -152,7 +137,7 @@ static VLCUpdate *_o_sharedInstance = nil;
[saveFilePanel setCanSelectHiddenExtension: YES];
[saveFilePanel setCanCreateDirectories: YES];
[saveFilePanel beginSheetForDirectory:nil file:
[[o_urlOfBinary componentsSeparatedByString:@"/"] lastObject]
[[[NSString stringWithUTF8String: p_u->release.psz_url] componentsSeparatedByString:@"/"] lastObject]
modalForWindow: o_update_window
modalDelegate:self
didEndSelector:sel
......@@ -173,8 +158,8 @@ static VLCUpdate *_o_sharedInstance = nil;
- (IBAction)okay:(id)sender
{
/* just close the window */
[o_update_window close];
/* just hides the window */
[o_update_window orderOut: self];
}
- (IBAction)changeCheckUpdateOnStartup:(id)sender
......@@ -182,173 +167,54 @@ static VLCUpdate *_o_sharedInstance = nil;
[self setShouldCheckUpdate: [sender state]];
}
- (void)checkForUpdate
- (void)updateManagement:(vlc_bool_t)b_success
{
/* We may not run on first thread */
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
p_u = update_New( p_intf );
update_Check( p_u, VLC_FALSE );
update_iterator_t *p_uit = update_iterator_New( p_u );
BOOL releaseChecked = NO;
BOOL gettingReleaseNote = NO;
int x = 0;
NSString * pathToReleaseNote;
pathToReleaseNote = [NSString stringWithFormat:
@"/tmp/vlc_releasenote_%d.tmp", mdate()];
[[NSUserDefaults standardUserDefaults] setObject: [NSDate date] forKey: kPrefUpdateLastTimeChecked];
if( p_uit )
if( !b_success ||
update_CompareReleaseToCurrent( p_u ) != UpdateReleaseStatusNewer )
{
p_uit->i_rs = UPDATE_RELEASE_STATUS_NEWER;
p_uit->i_t = UPDATE_FILE_TYPE_ALL;
update_iterator_Action( p_uit, UPDATE_MIRROR );
while( update_iterator_Action( p_uit, UPDATE_FILE) != UPDATE_FAIL )
{
msg_Dbg( p_intf, "parsing available updates, run %i", x );
/* if the announced item is of the type "binary", keep it and display
* its details to the user. Do similar stuff on "info". Do both
* only if the file is announced as stable */
if( p_uit->release.i_type == UPDATE_RELEASE_TYPE_STABLE )
{
if( p_uit->file.i_type == UPDATE_FILE_TYPE_INFO )
{
msg_Dbg( p_intf, "release note found, desc = %s",
p_uit->file.psz_description );
[o_fld_releaseNote setString:
[NSString stringWithUTF8String:
(p_uit->file.psz_description)]];
/* download our release note
* We will read the temp file after this loop */
update_download( p_uit, (char *)[pathToReleaseNote UTF8String] );
gettingReleaseNote = YES;
}
else if( p_uit->file.i_type == UPDATE_FILE_TYPE_BINARY )
{
msg_Dbg( p_intf, "binary found, version = %s, "
"url=%s, size=%i MB", p_uit->release.psz_version,
p_uit->file.psz_url,
(int)((p_uit->file.l_size / 1024) / 1024) );
[o_fld_currentVersionAndSize setStringValue:
[NSString stringWithFormat:
_NS("The latest VLC media player release "
"is %s (%i MB to download)."),
p_uit->release.psz_version, ((p_uit->file.l_size
/ 1024) / 1024)]];
if( o_urlOfBinary )
[o_urlOfBinary release];
o_urlOfBinary = [[NSString alloc] initWithUTF8String:
p_uit->file.psz_url];
[o_fld_status setStringValue: _NS("This version of VLC is the latest available.")];
[o_btn_DownloadNow setEnabled: NO];
}
if( p_uit->release.i_status == UPDATE_RELEASE_STATUS_NEWER &&
!releaseChecked )
else
{
/* our version is outdated, let the user download the new
* release */
[o_fld_status setStringValue: _NS("This version of VLC "
"is outdated.")];
[o_fld_releaseNote setString: [NSString stringWithUTF8String: (p_u->release.psz_desc)]];
[o_fld_status setStringValue: _NS("This version of VLC is outdated.")];
[o_fld_currentVersion setStringValue: [NSString stringWithFormat:
_NS("The current release is %d.%d.%d%c."), p_u->release.i_major,
p_u->release.i_minor, p_u->release.i_revision, p_u->release.extra]];
[o_btn_DownloadNow setEnabled: YES];
msg_Dbg( p_intf, "this version of VLC is outdated" );
/* put the mirror information */
msg_Dbg( p_intf, "used mirror: %s, %s [%s]",
p_uit->mirror.psz_name, p_uit->mirror.psz_location,\
p_uit->mirror.psz_type );
/* make sure that we perform this check only once */
releaseChecked = YES;
/* Make sure the update window is showed in case we have something */
[o_update_window center];
[o_update_window displayIfNeeded];
[o_update_window makeKeyAndOrderFront: self];
}
else if(! releaseChecked )
{
[o_fld_status setStringValue: _NS("This version of VLC "
"is the latest available.")];
[o_btn_DownloadNow setEnabled: NO];
msg_Dbg( p_intf, "current version is up-to-date" );
releaseChecked = YES;
}
}
x += 1;
}
update_iterator_Delete( p_uit );
/* wait for our release notes if necessary, since the download is done
* by another thread -- this does usually take 300000 to 500000 ms */
if( gettingReleaseNote )
{
int i = 0;
while( [[NSFileManager defaultManager] fileExistsAtPath: pathToReleaseNote] == NO )
{
msleep( 100000 );
i += 1;
if( i == 150 )
{
/* if this takes more than 15 sec, exit */
msg_Warn( p_intf, "download took more than 15 sec, exiting" );
break;
}
}
msg_Dbg( p_intf, "waited %i ms for the release notes", (i * 100000) );
msleep( 500000 );
/* let's open our cached release note and display it
* we can't use NSString stringWithContentsOfFile:encoding:error:
* since it is Tiger only */
NSString * releaseNote = [[NSString alloc] initWithData:
[NSData dataWithContentsOfFile: pathToReleaseNote]
encoding: NSISOLatin1StringEncoding];
if( releaseNote )
[o_fld_releaseNote setString: releaseNote];
/* delete the file since it isn't needed anymore */
BOOL myBOOL = NO;
myBOOL = [[NSFileManager defaultManager] removeFileAtPath:
pathToReleaseNote handler: nil];
}
else
{
/* don't confuse the user, but make her happy */
[o_fld_status setStringValue: _NS("This version of VLC "
"is the latest available.")];
[o_btn_DownloadNow setEnabled: NO];
msg_Dbg( p_intf, "current version is up-to-date" );
}
}
[pool release];
}
- (void)performDownload:(NSString *)path
static void updateCallback( void * p_data, vlc_bool_t b_success )
{
update_iterator_t *p_uit = update_iterator_New( p_u );
if( p_uit )
{
update_iterator_Action( p_uit, UPDATE_MIRROR );
while( update_iterator_Action( p_uit, UPDATE_FILE) != UPDATE_FAIL )
{
if( p_uit->release.i_type == UPDATE_RELEASE_TYPE_STABLE &&
p_uit->release.i_status == UPDATE_RELEASE_STATUS_NEWER &&
p_uit->file.i_type == UPDATE_FILE_TYPE_BINARY )
{
/* put the mirror information */
msg_Dbg( p_intf, "used mirror: %s, %s [%s]",
p_uit->mirror.psz_name, p_uit->mirror.psz_location,
p_uit->mirror.psz_type );
[(id)p_data updateManagement: b_success];
}
/* that's our binary */
update_download( p_uit, (char *)[path UTF8String] );
}
}
- (void)checkForUpdate
{
p_u = update_New( VLCIntf );
if( !p_u )
return;
update_Check( p_u, updateCallback, self );
update_iterator_Delete( p_uit );
}
[[NSUserDefaults standardUserDefaults] setObject: [NSDate date] forKey: kPrefUpdateLastTimeChecked];
}
[o_update_window close];
- (void)performDownload:(NSString *)path
{
update_Download( p_u, (char*)[path UTF8String] );
[o_btn_DownloadNow setEnabled: NO];
[o_update_window orderOut: self];
update_Delete( p_u );
}
@end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment