"Original" I understand the Automatic Update-client update process

Source: Internet
Author: User

Creates an update thread that interacts with the UI main thread through a message.
1, go to http://version.mygame.com/check.php? Channelid=%d&appver=%d&resver=%d Gets the latest version information for the client. Use curl to get the code as follows, as for Curl's specific parameters, man or search engine will tell you the answer

1 Staticsize_t Funcgethttptext (void*ptr, size_t size, size_t nmemb,void*UserData) {2size_t retsize = size*Nmemb;3     string* Pcontent = (string*) UserData;4     if(pcontent) {5Pcontent->append ((Char*) ptr, retsize);6}returnretsize;7 }8Curlcode Gethttptext (Const string& strURL,string&Strhttptext) {9curl* PCurl =curl_easy_init ();Ten     if(!PCurl) { One         returnCurl_last; A     } - strhttptext.clear (); -Curl_easy_setopt (PCurl, Curlopt_connecttimeout, -); theCurl_easy_setopt (PCurl, Curlopt_nosignal,1); -Curl_easy_setopt (PCurl, Curlopt_forbid_reuse,1); -Curl_easy_setopt (PCurl, Curlopt_ssl_verifypeer,0L); - curl_easy_setopt (PCurl, Curlopt_url, Strurl.c_str ()); + curl_easy_setopt (PCurl, curlopt_writefunction, funcgethttptext); -Curl_easy_setopt (PCurl, Curlopt_writedata, &strhttptext); +Curlcode err =Curl_easy_perform (pCurl); A     if(Err = =CURLE_OK) { at         intSZ =0; -Curl_easy_getinfo (PCurl, Curlinfo_http_code, &sz); -         if(SZ! = $) && (sz! =206)) { -             //OK or not modify -Err =Curl_last; -         } in     } - Curl_easy_cleanup (pCurl); to     returnerr; +}

Resolves the returned string.
1: Large version of the update, Pop-up dialog box, prompting the need for a large version of the update, the user can choose "Update", "Cancel". After the cancellation, exit the app and click Update to enter the process below.
Android: Download the appropriate apk from the returned URL and reload it (reload only for app, not reset resources),
Ios:adhoc is updated by the way code opens the URL. The code is as follows

[[UIApplication sharedapplication] Openurl:[nsurl urlwithstring:@ "itms-services://?action= Download-manifest&url==https://raw.githubusercontent.com/xxxxxhttp.plist"];

AppStore: Then open the AppStore app for updates, the code is as follows

[[UIApplication sharedapplication] Openurl:[nsurl urlwithstring:@ ""];

This will jump out of the current app and go to the AppStore app details page.
2: The local resource version number is 0 and the initial package is downloaded. 3: Download diff package for local resource version >0
Determine whether the local downloaded temporary file size is the same as the size of the extranet file, and if it is not the same, the breakpoint downloads the external network file. Curl supports breakpoint download, the code is as follows

1 Char rangbuf[0  }; 2 " %d- " , nrangefrom); 3 curl_easy_setopt (PCurl, Curlopt_range, rangbuf);

In addition, the download needs to determine the 3g environment problem, if in the 3g environment, downloaded files more than a certain size (such as 30M), then prompts the player whether to download, the player chooses whether to download. Because we download modules that are multithreaded, the main thread and multithreading communicate through the mutex.
Download Thread:

1  while(1) {2This_thread::sleep_for (Chrono::milliseconds ( -));3Std::unique_lock<std::mutex>Locker (m_mtxconfirm);4    if(M_eupdateconfirm = =Updateimplconfirm::update_unknow) {5This_thread::yield();6}Else{7        Break;8    }9 }Ten if(m_eupdateconfirm = = Updateimplconfirm::update_reject) {//Reject Update OnePostMessage (Newuserrejectmessage (Updatestate::eupdatestatedownloadfile)); AM_eupdateconfirm =Updateimplconfirm::update_unknow; -     returnCurl_last; -}

Ui:

 1  void   Confirmcontinue () { 2  Std::lock_guard <std::mutex> Autolock (m_mtxconfirm);  3  m_eupdateconfirm = updateimplconfirm::update _continue;  4   5  void   Confirmreject () { 6  std::lock_guard<std::mutex> Autolock (m_mtxconfirm);  7  m_eupdateconfirm = updateimplconfirm::update _reject;  8 } 

After the download is complete, the file size and MD5 are compared, if different ... Delete the file and download it again.
After successful, unzip the file to the writable directory, read the index file for data parsing, copy the appended file, overwrite the file to the resource directory for overwriting, delete the file, then delete the corresponding file of the resource directory. Check the resources, traverse the local resource file for MD5 comparison, if not the same, then go to the extranet to download the scattered files for overwriting. Clean up the temp directory and delete the index file. The resource update is complete.
4. The resource version is greater than 0 and matches the server resource version without updating.
Other, error "Server timeout, return error, = =", display the "Retry" button to retry.

"Original" I understand the Automatic Update-overview
"Original" I understand Automatic Updates-environment building and protocol development
"Original" I understand the Automatic update-extranet Web server configuration
"Original" I understand the Automatic Update-app release and background publishing
"Original" I understand the Automatic Update-resource packaging process
"Original" I understand the Automatic Update-client update process
"Original" I understand the automatic update-Knowledge point explanation

The server in this article uses the Linode,linode is what does not need to introduce too much.
Interested children's shoes can be registered via https://www.linode.com/?r=000161937771838e320f2bda5fef0dbad54ad86c server,
The number after r is my referral code, if you use the above recommendation code I recommend, and keep 3 months is an online account, then I will be three months after the credit of 20 dollars,
This means you can use the one-month minimum $19.95 Linode VPS.
Referrals reward you are refer people to Linode.
If someone signs up using your referral code,
You'll receive a credits of $20.00, so long as the person referred remains a active customer for.

Original "I understand the Automatic Update-client update process

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.