Révision 3898

TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/p2/plugins/TXMUpdateHandler.java (revision 3898)
59 59
	public Object execute(ExecutionEvent event) {
60 60
		
61 61
		// // disabled since java is no more shipped within TXM feature file copy commands
62
//		if (OSDetector.isFamilyWindows() && !isWindowsAdministratorUser()) {
63
//			TXMMessageBox.show(HandlerUtil.getActiveShell(event), TXMUIMessages.updateWarning, TXMUIMessages.abortingWindowsUpdate, SWT.ICON_WARNING);
64
//			Log.warning("Update canceled");
65
//			return null;
66
//		}
62
		//		if (OSDetector.isFamilyWindows() && !isWindowsAdministratorUser()) {
63
		//			TXMMessageBox.show(HandlerUtil.getActiveShell(event), TXMUIMessages.updateWarning, TXMUIMessages.abortingWindowsUpdate, SWT.ICON_WARNING);
64
		//			Log.warning("Update canceled");
65
		//			return null;
66
		//		}
67 67
		
68 68
		String key = event.getParameter("org.txm.rcp.parameters.update"); //$NON-NLS-1$
69 69
		if ("true".equals(key)) { //$NON-NLS-1$
......
87 87
		
88 88
		// Hacking p2 profile to be able to update installation directory even if
89 89
		// -configuration is set
90
		
91
		ProvisioningUI pui = ProvisioningUI.getDefaultUI();
92
		IProvisioningAgent agent = pui.getSession().getProvisioningAgent();
93
		
90 94
		try {
91 95
			Log.info("Looking for TXM updates..."); //$NON-NLS-1$
92 96
			
......
95 99
			console.activate();
96 100
			ConsolePlugin.getDefault().getConsoleManager().refresh(console);
97 101
			
98
			ProvisioningUI pui = ProvisioningUI.getDefaultUI();
99
			
100 102
			String profileId = pui.getProfileId();
101
			IProvisioningAgent agent = pui.getSession().getProvisioningAgent();
102 103
			
104
			
103 105
			if (agent != null) {
104 106
				IProfileRegistry profileRegistry = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME);
105 107
				
......
138 140
			if (!isUpdateSiteAvailable()) {
139 141
				return false;
140 142
			}
141
			
142
			addDefaultUpdateSites(agent);
143
			addDefaultPluginSites(agent);
144
			
145
			// add beta repos if needed
146
			// from bundle org.eclipse.equinox.p2.console
147
			
148
			Object ret = super.execute(event);
149
			Log.info(TXMUIMessages.Done);
150
			
151
			return ret;
152 143
		}
153 144
		catch (Exception e) {
154 145
			Log.severe(TXMUIMessages.bind(TXMUIMessages.CouldNotUpdateTXMP0, e));
155 146
			Log.printStackTrace(e);
147
			return false;
156 148
		}
157
		return null;
149
		
150
		addDefaultUpdateSites(agent);
151
		addDefaultPluginSites(agent);
152
		
153
		// add beta repos if needed
154
		// from bundle org.eclipse.equinox.p2.console
155
		
156
		Object ret = super.execute(event);
157
		Log.info(TXMUIMessages.Done);
158
		
159
		return ret;
160
		
158 161
	}
159 162
	
160 163
	public static boolean isUpdateSiteAvailable() {
......
170 173
			return false;
171 174
		}
172 175
	}
173

  
176
	
174 177
	public static boolean isWindowsAdministratorUser() {
175 178
		String path = BundleUtils.getInstallDirectory();// System.getProperty("osgi.instance.area");
176 179
		if (!path.startsWith("C:/Program Files/TXM")) { //$NON-NLS-1$
......
288 291
	}
289 292
	
290 293
	public static void addDefaultUpdateSites(IProvisioningAgent agent) {
294
		
291 295
		Version v = Activator.getDefault().getBundle().getVersion();
292 296
		String version = "" + v.getMajor() + "." + v.getMinor() + "." + v.getMicro(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
293 297
		String uriBase = TBXPreferences.getInstance().getString(TBXPreferences.UPDATESITE) + "/" + version + "/main"; //$NON-NLS-1$ //$NON-NLS-2$
294 298
		String uriDefault = uriBase + "/stable"; //$NON-NLS-1$
299
		
295 300
		try {
296 301
			URI repoUriDefault = new URI(uriDefault);
297 302
			addURL(agent, repoUriDefault, "stable"); //$NON-NLS-1$
......
301 306
		catch (Exception e) {
302 307
			Log.warning(TXMUIMessages.CouldNotAddTheDefaultUpdateRepository + uriDefault);
303 308
			Log.printStackTrace(e);
309
			
310
			try {
311
				URI repoUriDefault = new URI(uriDefault);
312
				removeURL(agent, repoUriDefault);
313
			} catch (Exception e2) {
314
				
315
			}
304 316
		}
305 317
		
306 318
		String updateLevel = RCPPreferences.getInstance().getString(RCPPreferences.UPDATE_LEVEL);
......
309 321
			betaMode = true;
310 322
		}
311 323
		Log.fine("Update mode: beta=" + betaMode); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
312
				
324
		
313 325
		String uriBeta = uriBase + "/beta";//$NON-NLS-1$
314 326
		try {
315 327
			URI repoUriBeta = new URI(uriBeta);
......
323 335
		catch (Exception e) {
324 336
			Log.warning(TXMUIMessages.bind(TXMUIMessages.CouldNotAddTheP0UpdateRepositoryP1, uriBeta, e));
325 337
			Log.printStackTrace(e);
338
			
339
			try {
340
				URI repoUriBeta = new URI(uriBeta);
341
				removeURL(agent, repoUriBeta);
342
			} catch (Exception e2) {
343
				
344
			}
326 345
		}
327 346
	}
328 347
	
......
341 360
		catch (Exception e) {
342 361
			Log.warning(TXMUIMessages.CouldNotAddTheDefaultExtensionRepository + uriDefault);
343 362
			Log.printStackTrace(e);
363

  
364
			try {
365
				URI repoUriDefault = new URI(uriDefault);
366
				removeURL(agent, repoUriDefault);
367
			} catch (Exception e2) {
368
				
369
			}
344 370
		}
345 371
		
346 372
		String updateLevel = RCPPreferences.getInstance().getString(RCPPreferences.UPDATE_LEVEL);
......
349 375
			betaMode = true;
350 376
		}
351 377
		Log.fine("Update levels: beta=" + betaMode); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
352
				
378
		
353 379
		String uriBeta = uriBase + "/beta";//$NON-NLS-1$
354 380
		try {
355 381
			URI repoUriBeta = new URI(uriBeta);
......
363 389
		catch (Exception e) {
364 390
			Log.warning(TXMUIMessages.bind(TXMUIMessages.CouldNotAddTheP0ExtensionsUpdateRepositoryP1, uriBeta, e));
365 391
			Log.printStackTrace(e);
392
			
393
			try {
394
				URI repoUriBeta = new URI(uriBeta);
395
				removeURL(agent, repoUriBeta);
396
			} catch (Exception e2) {
397
				
398
			}
366 399
		}
367 400
	}
368 401
	

Formats disponibles : Unified diff