Re: Auto Update for WEE?

new topic     » goto parent     » topic index » view thread      » older message » newer message
PeteE said...

I think this can be done, after I put the code on github. I think I can use std/net/http.e http_get() to download a file manifest containing the version number, file names and checksums. If the version number changes, then download files that have a different checksum.

I'm torn on whether to check for updates during startup. On startup, if the user has to wait for the http_get() due to a slow DNS resolve or slow connection, that's a little annoying. Maybe I could do the http_get in a separate task, but it's not clear if that will allow the main task to interact with the user. The wee.conf could also store the date of the last check, and only check for updates once per day. I would provide a menu option to check for updates.

DNS (i.e. host_by_name) is not tasking-enabled, so it will block other tasks.

But the rest of the process can be integrated into WEE using multi-tasking.

Here are the bits of code I added to WEE (in ui_win.e) to check for mock updates.

I needed a function to show a simple "OK" message box.

global function ui_message_box_ok(sequence title, sequence message) 
    atom result 
    result = c_func(MessageBox, {hMainWnd,  
      alloc_string(message), 
      alloc_string(title), 
      or_all({MB_APPLMODAL, MB_ICONINFORMATION, MB_OK})}) 
    free_strings() 
    return result = IDYES 
end function 

Here is the routine that "checks" for an update.

constant WEE_UPDATE_URL = "http://openeuphoria.org/index.wc" 
 
procedure check_version() 
 
    atom task_id = task_self() 
     
    -- sleep for a few seconds before checking 
    -- so we don't immediately bombard the user 
    task_delay( 3 ) 
    task_yield() 
     
    -- fetch the latest version information 
    object result = http_get( WEE_UPDATE_URL ) 
    if atom( result ) then 
      -- failed to check for updates 
      ui_message_box_error( "WEE Update", "An error occurred while checking for updates." ) 
    else 
      -- success, perform additional update steps 
      ui_message_box_ok( "WEE Update", "A new version is available." ) 
    end if 
     
    -- stop this task 
    task_suspend( task_id ) 
    task_yield() 
 
end procedure 

Here we create and schedule the task before showing the window and starting the event loop.

atom check_id = task_create( routine_id("check_version"), {} ) 
task_schedule( check_id, 1 ) 
 
c_proc(ShowWindow, {hMainWnd, SW_SHOWNORMAL}) 
c_proc(UpdateWindow, {hMainWnd}) 

And finally, we add a call to task_yield in the event loop.

while c_func(GetMessage, {msg, NULL, 0, 0}) do 
  if hFindDlg and c_func(IsDialogMessage,{hFindDlg,msg}) then 
    -- this message is handled by find dialog (thanks Jacques) 
    -- it makes the tab key work for find/replace dialogs 
  else 
    translate_editor_keys(msg) 
    junk = c_func(TranslateMessage, {msg}) 
    junk = c_func(DispatchMessage, {msg}) 
  end if 
  task_yield() 
end while 
SDPringle said...

Unix is only normally secure because only admin installs programs. If you do your day to day activities as a Limited User account on Windows, your exposure to threats is incredibly reduced. Now, if programs are updating themselves this means the user has write access to the editor. This is a bad thing. Check if you want to check, but please download to the download folder. I become root for the install process but normally I run my computer as a limited rights user. Viruses can infect good programs and misuse them.

Nah.

  1. Package the update into its own installer.
  2. Download the installer to a temporary location (e.g "Downloads").
  3. Launch the installer with admin permissions from the editor. ("runas" on Windows or "gksudo" on Linux)
  4. If the installer launched successfully (user allowed admin action), then quit the editor.

-Greg

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu