Index: trunk/xpressme_integration_kit/wp-content/plugins/xpressme/include/class-xpress-upgrader.php
===================================================================
--- trunk/xpressme_integration_kit/wp-content/plugins/xpressme/include/class-xpress-upgrader.php	(revision 698)
+++ trunk/xpressme_integration_kit/wp-content/plugins/xpressme/include/class-xpress-upgrader.php	(revision 698)
@@ -0,0 +1,78 @@
+<?php
+include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
+/**
+ * Core Upgrader class for WordPress. It allows for WordPress to upgrade itself in combiantion with the wp-admin/includes/update-core.php file
+ *
+ * @TODO More Detailed docs, for methods as well.
+ *
+ * @package WordPress
+ * @subpackage Upgrader
+ * @since 2.8.0
+ */
+class Xpress_Upgrader extends WP_Upgrader {
+
+	function upgrade_strings() {
+		$this->strings['up_to_date'] = __('XPressME Integration Kit is at the latest version.');
+		$this->strings['no_package'] = __('Upgrade package not available.');
+		$this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>&#8230;');
+		$this->strings['unpack_package'] = __('Unpacking the update&#8230;');
+		$this->strings['copy_failed'] = __('Could not copy files.');
+		$this->strings['make_config'] = __('Delete source wp-config.php.');
+		$this->strings['delete_failed'] = __('Could not delete files.');
+	}
+
+	function upgrade($current) {
+		global $wp_filesystem;
+
+		$this->init();
+		$this->upgrade_strings();
+
+		if ( !empty($feedback) )
+			add_filter('update_feedback', $feedback);
+
+		// Is an update available?
+		if ( !isset( $current->response ) || $current->response == 'latest' )
+			return new WP_Error('up_to_date', $this->strings['up_to_date']);
+
+		$res = $this->fs_connect( array(ABSPATH, WP_CONTENT_DIR) );
+		if ( is_wp_error($res) )
+			return $res;
+
+		$wp_dir = trailingslashit($wp_filesystem->abspath());
+
+		$download = $this->download_package( $current->package );
+		if ( is_wp_error($download) )
+			return $download;
+
+		$working_dir = $this->unpack_package( $download );
+		if ( is_wp_error($working_dir) )
+			return $working_dir;
+		$subdirs = $wp_filesystem->dirlist($working_dir,false);
+		foreach($subdirs as $subdir){
+			$subdir_name = $subdir['name'];
+		}
+		
+		$kit_dir = $working_dir .'/' .$subdir_name .'/xpressme_integration_kit/';
+		
+		// Copy update-core.php from the new version into place.
+		$update_xpress_file = 'wp-content/plugins/xpressme/include/update_xpress.php';
+//		if ( !$wp_filesystem->copy($kit_dir . $update_xpress_file, $wp_dir . $update_xpress_file, true) ) {
+//			$wp_filesystem->delete($working_dir, true);
+//			return new WP_Error('copy_failed', $this->strings['copy_failed']);
+//		}
+		$wp_filesystem->chmod($wp_dir . $update_xpress_file, FS_CHMOD_FILE);
+
+		require(ABSPATH . $update_xpress_file);
+
+		return update_xpress($kit_dir, $wp_dir);
+		
+	// Remove working directory
+		$wp_filesystem->delete($working_dir, true);
+		if ( !$wp_filesystem->delete($working_dir, true)){
+			return new WP_Error('delete_failed', $this->strings['delete_failed']);
+		}
+		show_message( __('Delete Working directory') );
+		$wp_filesystem->chmod($wp_dir . 'templates/', 0777);
+	}
+}
+
Index: trunk/xpressme_integration_kit/wp-content/plugins/xpressme/include/update_xpress.php
===================================================================
--- trunk/xpressme_integration_kit/wp-content/plugins/xpressme/include/update_xpress.php	(revision 698)
+++ trunk/xpressme_integration_kit/wp-content/plugins/xpressme/include/update_xpress.php	(revision 698)
@@ -0,0 +1,66 @@
+<?php
+/**
+ * XPressME Integration Kit upgrade functionality.
+ */
+
+/**
+ * Stores files to be deleted.
+ */
+global $_old_xpress_files;
+
+$_old_xpress_files = array(
+// 2.03	
+'wp-content/themes/xpress_default/images/titleline.jpg',
+'wp-content/themes/xpress_default/ja.mo',
+'wp-content/themes/xpress_default/ja.po',
+// 2.3.0
+'wp-content/themes/xpress_default/ja_EUC.mo',
+'wp-content/themes/xpress_default/ja_EUC.po',
+'wp-content/themes/xpress_default/ja_UTF.mo',
+'wp-content/themes/xpress_default/ja_UTF.po',
+);
+
+/**
+ * Upgrade the XPressME .
+ *
+ * @param string $from New release unzipped path.
+ * @param string $to Path to old WordPress installation.
+ * @return WP_Error|null WP_Error on failure, null on success.
+ */
+function update_xpress($from, $to) {
+	global $wp_filesystem, $_old_xpress_files, $wpdb;
+	show_message( __('Disable overwrite of wp-config.php...') );
+	// remove wp-config.php from the new version into place.
+	$wp_config = $from . 'wp-config.php';
+	if ( !$wp_filesystem->delete($wp_config, true)){
+		return new WP_Error('delete_failed', $this->strings['delete_failed']);
+	}
+
+	// Copy new versions of XPressME Integration Kit files into place.
+	show_message( __('Copy new versions of XPressME Integration Kit files into place...') );
+	$result = copy_dir($from . $distro, $to);
+	if ( is_wp_error($result) ) {
+		$wp_filesystem->delete($maintenance_file);
+		$wp_filesystem->delete($from, true);
+		return $result;
+	}
+
+	// Remove old files
+	show_message( __('Remove an unnecessary, old file...') );
+	foreach ( $_old_xpress_files as $old_file ) {
+		$old_file = $to . $old_file;
+		if ( !$wp_filesystem->exists($old_file) )
+			continue;
+		$wp_filesystem->delete($old_file, true);
+	}
+	show_message( __('Set templates directory chmod 777') );
+	$wp_filesystem->chmod($to . 'templates/', 0777);
+
+	// Remove working directory
+	$working_dir = dirname(dirname($from));
+	show_message( sprintf(__('Remove working directory(%s)...'),$working_dir) );
+	$wp_filesystem->delete($working_dir, true);
+
+}
+
+?>
Index: trunk/xpressme_integration_kit/wp-content/plugins/xpressme/include/xpress_upgrade.php
===================================================================
--- trunk/xpressme_integration_kit/wp-content/plugins/xpressme/include/xpress_upgrade.php	(revision 697)
+++ trunk/xpressme_integration_kit/wp-content/plugins/xpressme/include/xpress_upgrade.php	(revision 698)
@@ -1,8 +1,14 @@
 <?php
-function upgrade_page()
-{
+function  find_xpress_update( $version, $locale ){
+		$latest_version = get_option('xpressme_latest_version');
+		return (object)$latest_version;
+}
+	
+	
+function list_xpress_update( $update=null ) {
 	global $xoops_config,$xpress_config;
 	
 	$xpress_version = $xoops_config->module_version . $xoops_config->module_codename;
+	$xpress_version = '2.38';
 	$lang = WPLANG;
 
@@ -12,6 +18,5 @@
 	echo		'<div id="icon-options-general" class="icon32"><br /></div>'."\n";
 	echo		'<h2>' . __('XPressME Upgrade', 'xpressme') . "</h2><br>\n";
-	
-	if(get_xpress_latest_version()){
+	if( get_xpress_latest_version($check_url)){
 		$latest = get_option('xpressme_latest_version');
 		if ($latest) {
@@ -23,5 +28,5 @@
 
 
-		if (version_compare($xpress_version, $latest_version, '>')){
+		if (version_compare($xpress_version, $latest_version, '>')){ 
 				echo '<h3 class="response">';
 				printf(__('You are using a XPressME Integration Kit development version (%1$s). Cool! Please <a href="%2$s">stay updated</a>.', 'xpressme') , $xpress_version , $latest['develop_url']);
@@ -29,22 +34,32 @@
 
 		} else if (version_compare($xpress_version, $latest_version, '<')) {
-			echo	'<h3 class="response">'. __('There is a new version of XPressME Integration Kit available for upgrade', 'xpressme') . '</h3>';
-			echo '<p>';
-			printf(__('You can upgrade to version %s download the package and install it manually:', 'xpressme'),$latest_version);
-			echo '</p>';
-			echo '<a class="button" href="' . $package . '">';
-			printf(__('Download %s', 'xpressme') , $latest_version);
-			echo '</a>';
-			
+			echo '<h3 class="response">';
+			_e( 'An updated version of XPressME Integration Kit is available.' );
+			echo '</h3>';
+
 			if ($latest['diff_response'] == 'diff_exists'){
-				echo '<p>';
-				printf(__('You can download the differential file from version %s to %s and upgrade it manually:', 'xpressme'),$xpress_version,$latest['diff_latest_version']);
-				echo '</p>';
-				echo '<a class="button" href="' . $latest['diff_package'] . '">';
-					printf(__('Download differential file for %s', 'xpressme') , $latest['diff_latest_version']);
-				echo '</a>';
+//				echo '<p>';
+//				printf(__('You can download the differential file from version %s to %s and upgrade it manually:', 'xpressme'),$xpress_version,$latest['diff_latest_version']);
+//				echo '</p>';
+				$download_diff  ='<a class="button" href="' . $latest['diff_package'] . '">';
+//				$download_diff .=	sprintf(__('Download differential file for %s', 'xpressme') , $latest['diff_latest_version']);
+				$download_diff .=	sprintf(__('Download differential file for %s', 'xpressme') , $xpress_version);
+				$download_diff .='</a>';
 			}
+			$message = 	sprintf(__('You can update to <a href="http://codex.wordpress.org/Version_%1$s">XPressME Integration Kit Ver %2$s</a> automatically or download the package and install it manually:'), $update->current, $latest_version);
+			$submit = __('Update Automatically');
+			$form_action = 'admin.php?page=upgrade_page&action=do-xpress-upgrade';
+			$download = sprintf(__('Download %s', 'xpressme') , $latest_version);
+			$show_buttons = true;
+
 		} else {
-			echo	'<h3 class="response">'. __('You have the latest version of XPressME Integration Kit. You do not need to upgrade', 'xpressme') . '</h3>';
+			echo '<h3>';
+			printf(__('You have the latest version of XPressME Integration Kit Ver.%s.'),$xpress_version);
+			echo '</h3>';
+
+			$message = __('You have the latest version of XPressME Integration Kit. You do not need to upgrade', 'xpressme');
+			$submit = __('Re-install Automatically');
+			$form_action = 'update-core.php?action=do-core-reinstall';
+
 		}
 		
@@ -74,8 +89,97 @@
 		}
 
+		echo '<p>';
+		echo $message;
+		echo '</p>';
+		echo '<form method="post" action="' . $form_action . '" name="upgrade" class="upgrade">';
+	//	wp_nonce_field('upgrade-core');
+		echo '<p>';
+		echo '<input name="version" value="'. esc_attr($update->current) .'" type="hidden"/>';
+		echo '<input name="locale" value="'. esc_attr($update->locale) .'" type="hidden"/>';
+		if ( $show_buttons ) {
+			echo '<input id="upgrade" class="button" type="submit" value="' . esc_attr($submit) . '" name="upgrade" />&nbsp;';
+			echo '<a href="' . esc_url($package) . '" class="button">' . $download . '</a>&nbsp;';
+			echo $download_diff;
+		}
+		echo '</form>';
 	} else {
 		echo '<h3 class="response">';
 		printf(__('There is no response from <a href="%s">version check API</a> now. sorry, please confirm it after.', 'xpressme'),$check_url);
 		echo	"</div>\n";
+	}
+}
+
+
+function xpress_update_core($current) {
+	include_once ABSPATH . 'wp-content/plugins/xpressme/include/class-xpress-upgrader.php';
+	$upgrader = new Xpress_Upgrader();
+	return $upgrader->upgrade($current);
+}
+
+function do_xpress_upgrade( $reinstall = false ) {
+	global $wp_filesystem;
+
+	if ( $reinstall )
+		$url = 'update-xpress.php?action=do-xpress-reinstall';
+	else
+		$url = 'update-xpress.php?action=do-xpress-upgrade';
+	$url = wp_nonce_url($url, 'upgrade-xpress');
+	if ( false === ($credentials = request_filesystem_credentials($url, '', false, ABSPATH)) )
+		return;
+
+	$version = isset( $_POST['version'] )? $_POST['version'] : false;
+	$locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
+	$update = find_xpress_update( $version, $locale );
+//	$update = true;
+	if ( !$update )
+		return;
+
+
+	if ( ! WP_Filesystem($credentials, ABSPATH) ) {
+		request_filesystem_credentials($url, '', true, ABSPATH); //Failed to connect, Error and request again
+		return;
+	}
+?>
+	<div class="wrap">
+	<?php screen_icon(); ?>
+	<h2><?php _e('Update XPressME Integration Kit'); ?></h2>
+<?php
+	if ( $wp_filesystem->errors->get_error_code() ) {
+		foreach ( $wp_filesystem->errors->get_error_messages() as $message )
+			show_message($message);
+		echo '</div>';
+		return;
+	}
+
+	if ( $reinstall )
+		$update->response = 'reinstall';
+
+	$result = xpress_update_core($update, 'show_message');
+
+	if ( is_wp_error($result) ) {
+		show_message($result);
+		if ('up_to_date' != $result->get_error_code() )
+			show_message( __('Installation Failed') );
+	} else {
+		show_message( __('XPressME Integration Kit updated successfully') );
+		$update_url = 'http://localhost/cube/modules/xp_test/admin/update.php';
+		show_message( '<strong>' . __('Actions:') . '</strong> <a href="' . esc_url( $update_url ) . '">' . __('Go to Module Update') . '</a>' );
+	}
+	echo '</div>';
+}
+
+
+
+
+function upgrade_page()
+{
+	if ( ! current_user_can('update_plugins') )
+	wp_die(__('You do not have sufficient permissions to update XPressME Integration Kit for this site.'));
+	$action = isset($_GET['action']) ? $_GET['action'] : 'upgrade-xpress';
+	$upgrade_error = false;
+	if ( 'upgrade-xpress' == $action ) {
+		list_xpress_update();
+	} elseif ( 'do-xpress-upgrade' == $action) {
+		do_xpress_upgrade();
 	}
 }
@@ -103,5 +207,5 @@
 }
 
-function get_xpress_latest_version(){
+function get_xpress_latest_version($check_url){
 	global $wp_version, $wpdb, $wp_local_package;
 	global $xoops_config;
@@ -110,5 +214,5 @@
 	$lang = WPLANG;
 
-	$check_url = "http://ja.xpressme.info/version_check/index.php?version=$xpress_version&lang=$lang";
+//	$check_url = "http://ja.xpressme.info/version_check/index.php?version=$xpress_version&lang=$lang";
 	$request_options = array(
 	'timeout' => 3,
