Web version checking and adding sound effects to your application

Source: Internet
Author: User
Tags anonymous ftp header ftp access

In a 20,034-month column, you described how to implement a class called Cwebversion, which allows you to access a file on the network to check the version of the software, prompting the user to update the program when the version expires. Your implementation uses FTP to download files, but my site's ISP is not allowed to use anonymous FTP connections and can only log on by user and password. Can I use HTTP instead of FTP to download the version file as a Web page?

If you haven't read the 20,034-month column, I'll give you a brief introduction to the Cwebversion class, which I've written to compare the program version number to a class that's stored on the Web. I use this class in the Tracewin program to inform the user when a new version of the download is available.

Yes, you can use HTTP, but you don't have to convert the file. I really should use HTTP in my original implementation because HTTP is more widely used than FTP. Many WEB service providers do not allow anonymous FTP access for security reasons, but FTP is more efficient for file transfers (which is why I use FTP), and HTTP is good for getting simple text files.

Cwebversion reads a text file, and the version data in the file is separated by commas into four parts: a high/low primary/minor version number. The way to use this is:

if (CWebVersion::Online()) {
  CWebVersion webver("www.mysite.com");
  if (webver.ReadVersion("myversion.txt")) {
    // dwVersionMS and dwVersionLS now
    // hold the version numbers
  }
}

Static member function Cwebversion::online called:: InternetQueryOption, using internet_option_connected_state as a parameter to check whether this computer is connected to the INTERNET. If it is already connected, then cwebversion::readversion reads the version file from your Web site. You can then compare the read version number with the version number compiled in the application, which is typically in versioninfo or dllgetversion resources (see: "How to obtain version information for a dynamic link library"). The original cwebversion use FTP to get the file; I use HTTP to process this article instead. Using MFC's Wininet class, it is easy to read files over HTTP on the Web:

// in CWebVersion::ReadVersion
CInternetSession session(_T("MySession"));
CHttpConnection* pConn =
session.GetHttpConnection("www.dilascia.com",INTERNET_DEFAULT_HTTP_PORT);
CHttpFile* pFile =
pConn->OpenRequest(CHttpConnection::HTTP_VERB_GET, "TraceWinVer.txt");
pFile->SendRequest();

The code above is intended to download the file www.dilascia.com/TraceWinVer.txt. After calling SendRequest, you can call CHttpFile::QueryInfoStatusCode to get the status-for example, the status code that the file is not found is 404,200 for success (complete list of status codes see Wininet.h header file)- -Then call Chttpfile::read to read the file into your buffer, which is done by cwebversion::readversion, and then call scanf and parse the contents of the file according to the "Mhi,mlo,mhi,mlo" format, where Mhi,mlo, Mhi,mlo the high and low words (WORDs) representing both the major and minor versions. Cwebversion saves this information in Cwebversion::d wmajorversion and Cwebversion::d wminorversion. Complete code See Figure 1.

To test cwebversion, I wrote a program GetVersion.exe (see Figure 2), when I first tested cwebversion on my own site, I named the version file TraceWinVer.dat. Although the file is already in place, but the download times 404 error (file does not exist). At first I thought I had to add the. dat accept file type in the request header:

static LPCTSTR MyHeaders = _T("Accept: text/dat\r\n");
...
pHttpFile->AddRequestHeaders(MyHeaders);

Figure 2 Test Program

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.