wlalth 0 Newbie Poster

Hi, i have a stange problem with a my patch system. If two of the files are not exist on the users computer, patcher downloads them perfectly.

If first file exist and different from the web site, patcher also downloads it perfectly. However, if the second file are exist on users computer and its different from the file which is uploaded on website, patcher don't downloads it. Download function triggered and overwrite on file but download wasn't start.

Its completely my system, so maybe it is not the best way for the make a updater.

What is wrong is following code?

ps. sorry for message boxes i don't translate them, but i think thats no matter.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Diagnostics;
using System.Timers;
using System.Security;
using System.Security.Cryptography;
using System.Threading;




namespace update_final
{
    public partial class Form1 : Form
    {
        int x = 1;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.ControlBox = false;
            guncelle();

        }

        private bool denetle(string dosyaismi, string dosyayolu)
        {
            string netdboyu = "0";
            string userdboyu = "0";

            WebClient bak = new WebClient();

            try        // bakalim boyle bir dosya var mi???
            {

                FileInfo userdosya = new FileInfo(dosyaismi);
                userdboyu = userdosya.Length.ToString();
            }

            catch (FileNotFoundException)
            {
                return true; // yokmuş o zaman indir

            }


            try // bakalım nete erişebiliyo muyuz???
            {
                WebRequest requ = HttpWebRequest.Create(dosyayolu + dosyaismi);
                requ.Method = "HEAD";

                WebResponse resu = requ.GetResponse();
                netdboyu = resu.ContentLength.ToString();

            }

            catch (SystemException)
            {         
                return false; // erişemedik bu dosyayı atlayıver
            }

            if (userdboyu == netdboyu)
            {
                return false;
            }

            else
            {
                return true;
            }


        }
        

        private void indir(string neyi, string nerden)
        {
            System.Threading.Thread.Sleep(1000);
            label1.Text = "Güncellenen dosya: " + neyi;
            WebClient indir = new WebClient();
            indir.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
            indir.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
            indir.DownloadFileAsync(new Uri(nerden + neyi), (neyi));
        }



        private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            progressBar1.Value = e.ProgressPercentage;
        }


        private void Completed(object sender, AsyncCompletedEventArgs e)
        {
            x++;
            guncelle();
        }


        private void guncelle()
        {
            switch (x)
            {
                case 1:
                    if (denetle("file 1", "http://mysitegoeshere/") == true)
                    {
                        indir("file 1", "http://mysitegoeshere/");
                    }

                    else
                    {
                        x++;
                        guncelle();
                    }

                    break;
                case 2:
                    if (denetle("file 2", "http://mysitegoeshere/") == true)
                    {
                        indir("file 2", "http://mysitegoeshere/");
                    }

                    else
                    {
                        x++;
                        guncelle();
                    }
                    break;

                case 3:
                    System.Threading.Thread.Sleep(2000);
                    calistir("file 1"); // main exe of my program
                    Application.Exit();
                    break;

            }

        }


        private void calistir(string neyi)
        {
            Process firot = new Process();
            try
            {
                firot.StartInfo.FileName = neyi;
                firot.Start();
            }


            catch (FileNotFoundException)
            {
                MessageBox.Show("Kurulum hatalı yapılmış. Lütfen güncelleme modülünü tekrar çalıştırın");

            }

            catch (System.ComponentModel.Win32Exception)
            {
                MessageBox.Show("Kurulum hatalı yapılmış. Lütfen güncelleme modülünü tekrar çalıştırın");
            }

            Close();
        }


    }


}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.