Exemple #1
0
        private void LoadApp(object sender, EventArgs e)
        {
            if (startTimer != null)
            {
                startTimer.Stop();
            }
            int code = 0;

            try
            {
                this.Enabled = false;
                bool firstconnect = false;
tryingToCreate:
                {
                    try
                    {
                        if (!Directory.Exists(App.path))
                        {
                            Directory.CreateDirectory(App.path);
                            firstconnect = true;
                        }
                    }
                    catch
                    {
                        if (App.path == Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/mivzaklive")
                        {
                            new Error("לתוכנה חסרות הרשאות לתיקיות Program Files / My Documents. נא להוסיף הרשאות או להפעיל כמנהל.").ShowDialog();
                            return;
                        }
                        else
                        {
                            App.path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/mivzaklive";
                            goto tryingToCreate;
                        }
                    }
                }
                code++;
                RegistryKey reg = Registry.CurrentUser.CreateSubKey("MivzakLive");
                if (firstconnect)
                {
                    reg.SetValue("Dir", App.path);
                }
                else
                {
                    App.path = reg.GetValue("Dir", Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "/mivzaklive").ToString();
                }
                reg.Close();
                code++;
                if (Process.GetProcessesByName("Alarm").Length > 1)
                {
                    new Error("התוכנה כבר פועלת.").ShowDialog();
                    return;
                }
                Loading load = new Loading(false);
                load.Show();
                load.progressBar1.Minimum = 0;
                load.progressBar1.Maximum = 12;
                load.progressBar1.Value   = 0;
                load.label1.Refresh();
                load.progressBar1.Refresh();
                if (!App.IsConnectedToInternet())
                {
                    new Error("לשימוש בתוכנה זו עליך להיות מחובר לאינטרנט.").ShowDialog();
                    return;
                }
                load.progressBar1.Value++;
                code++;
                File.WriteAllText(App.path + "/conf.tmp", App.ReadFromWeb(App.programurl + "configuration.cfg"));
                load.progressBar1.Value++;
                code++;
                if (App.INIGetKey(App.path + "/conf.tmp", "Lock") == "1")
                {
                    new Error(App.ReadFromWeb(App.INIGetKey(App.path + "/conf.tmp", "LockMessage"))).ShowDialog();
                    return;
                }
                client = new WebClient();
                load.progressBar1.Value++;
                code++;
                if (firstconnect)
                {
                    Directory.CreateDirectory(App.path);
                    for (int i = 0; i < App.files.Length; i++)
                    {
                        client.DownloadFile(App.programurl + "install/" + App.files[i], App.path + "/" + App.files[i]);
                    }
                }
                else
                {
                    bool testone = App.CheckFiles(1);
                    if (!testone)
                    {
                        new Error("קבצי התוכנה פגומים, הורד אותה מחדש (Error #1).").ShowDialog();
                        return;
                    }
                }
                load.progressBar1.Value++;
                code++;
                App.ReadConfiguration(App.path + "/setting.cfg", ' ', ref Variables.setting);
                load.progressBar1.Value++;
                code++;
                App.ReadConfiguration(App.path + "/" + Variables.setting["language"] + ".lang", '=', ref Variables.text);
                load.progressBar1.Value++;
                code++;
                if (!App.CheckFiles(2))
                {
                    new Error("קבצי התוכנה פגומים, הורד אותה מחדש (Error #2).");
                }
                load.progressBar1.Value++;
                code++;
                if (App.INIGetKey(App.path + "/conf.tmp", "NewestVersion") != App.version)
                {
                    load.Hide();
                    new UpdateVersion().ShowDialog();
                    return;
                }
                load.progressBar1.Value++;
                code++;
                string u = App.INIGetKey(App.path + "/conf.tmp", "Footer");
                if (u.EndsWith(".html"))
                {
                    webBrowser1.Visible = true;
                    pictureBox4.Visible = false;
                    webBrowser1.Url     = new Uri(u);
                }
                else
                {
                    webBrowser1.Visible = false;
                    pictureBox4.Visible = true;
                    client.DownloadFileAsync(new Uri(u), App.path + "/footer.jpg");
                    client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
                }
                load.progressBar1.Value++;
                code++;
                App.website = App.INIGetKey(App.path + "/conf.tmp", "Website");
                App.mail    = App.INIGetKey(App.path + "/conf.tmp", "Mail");
                File.Delete(App.path + "/conf.tmp");
                load.progressBar1.Value++;
                code++;
                rss  = new RSS(App.rssurl, true);
                mivz = rss.GetLastItems(Notification.NotificationTypes.Any, MAX_UPDATES);
                Updates();
                load.progressBar1.Value++;
                code++;
                notifyIcon1.Visible        = true;
                toolStripStatusLabel2.Text = "V " + App.version;
                toolStripStatusLabel6.Text = App.mail;
                for (int i = 0; i < checkedListBox1.Items.Count; i++)
                {
                    checkedListBox1.SetItemChecked(i, Convert.ToInt32(Variables.setting["not" + (i + 1)].ToString()) == 1);
                }
                not     = new Not(this);
                fullnot = new FullNot();
                load.progressBar1.Value++;
                code++;
                LoadMyLanguage();
                code++;
                timer1.Start();
                load.Close();
                dataGridView1.ClearSelection();
                this.Enabled = true;
                this.Focus();
                if (firstconnect)
                {
                    ToolTip tt = new ToolTip();
                    tt.IsBalloon   = true;
                    tt.ToolTipIcon = ToolTipIcon.Info;
                    tt.Show("לשינוי שפה לחץ על כאן\nClick here to switch language", this, 0, 0, 5000);
                    //File.Move(Application.ExecutablePath, App.path + "/Alarm.exe");
                }
                if (File.Exists(App.path + "/Changelog.txt"))
                {
                    new Changelog().ShowDialog();
                    string startup = Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "/Alarm.exe";
                    if (File.Exists(startup))
                    {
                        File.Copy(Application.ExecutablePath, startup, true);
                    }
                }
                code++;
            }
            catch
            {
                if (File.Exists(App.path + "/conf.tmp"))
                {
                    File.Delete(App.path + "/conf.tmp");
                }
                new Error("נוצרה בעיית טעינה, אנא נסה שוב. אם הבעיה חוזרת על עצמה צור קשר במייל: " + App.mail + "\r\n(קוד בעיה: " + code + ")").ShowDialog();
            }
        }