Ejemplo n.º 1
0
        public void UpdateAppDB(string content)
        {
            //load data from remote db.
            this.myAppDB = (AppInfoDB)WinAptLib.ReadFromStream(typeof(AppInfoDB), content);

            for (int i = 0; i < myAppDB.Items.Count; i++)
            {
                ((AppInfoBase)myAppDB.Items[i]).setIndex(i);
            }

            //compare with local data
            foreach (AppInfoBase item in this.myConfig.Items)
            {
                int index = 0;
                //already contains, mark as needDownload
                if ((index = myAppDB.Contains(item)) != -1)
                {
                    ((AppInfoBase)myAppDB.Items[index]).setState(WinAptLib.Downloaded);
                }
                //has older version, mark as needUpdate
                if ((index = myAppDB.HasOldVersion(item)) != -1)
                {
                    ((AppInfoBase)myAppDB.Items[index]).setState(WinAptLib.NewVersion);
                    ((AppInfoBase)myAppDB.Items[index]).version = ((AppInfoBase)item).version;
                }
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("start to download information...");
            WinGetParser myApp = new WinGetParser();

            myApp.UpdateData();
            WinAptLib.WriteToFile(myApp.myAppInfoDB, @"appinfodb_en-US.xml");
        }
Ejemplo n.º 3
0
        public void InitApp()
        {
            //
            //TODO: add init code before main form show.
            //

            this.lbSplash.Text = MainForm.LocRM.GetString("strSplashLabelText");

            if (MainForm.myCmdMgr == null)
            {
                MainForm.myCmdMgr = new CmdMgr();
            }

            //if we already build one, no need to check the file.
            if (MainForm.myCmdMgr.Config == null)
            {
                //load config file
                if (File.Exists(configFile))
                {
                    MainForm.myCmdMgr.Config = (AppInfoConfig)WinAptLib.ReadFromFile(typeof(AppInfoConfig), configFile);
                }
                else
                {
                    //no config file, need to builder one
                    throw new Exception("new");
                }
            }
            //download update page.
            string content = "";

            this.lbSplash.Text = MainForm.LocRM.GetString("strSplashLabelLoadDB");
            lbSplash.Update();
            try
            {
                string fileName = MainForm.myCmdMgr.Config.usingDB;
                if (!File.Exists(fileName))
                {
                    this.lbSplash.Text = MainForm.LocRM.GetString("strSplashLabelDownloadDB");
                    lbSplash.Update();
                    progressBar1.Visible = true;
                    if (!WinAptLib.DownloadDbFile(MainForm.myCmdMgr.Config.updateUrl, progressBar1))
                    {
                        throw new Exception(string.Format(MainForm.LocRM.GetString("strSplashLabelDownloadError"), MainForm.myCmdMgr.Config.updateUrl));
                    }
                }
                content = WinAptLib.GetAppInfoContent(fileName);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                //save the config file, then quit program.
                WinAptLib.WriteToFile(MainForm.myCmdMgr.Config, configFile);
            }
            MainForm.myCmdMgr.UpdateAppDB(content);
        }
Ejemplo n.º 4
0
 private void UpdateForm_Shown(object sender, EventArgs e)
 {
     if (!WinAptLib.DownloadDbFile(url, this.proBar))
     {
         MessageBox.Show(string.Format(MainForm.LocRM.GetString("strSplashLabelDownloadError"), url));
     }
     timer1.Stop();
     Close();
 }
Ejemplo n.º 5
0
        internal void MergeDB(string newFile)
        {
            AppInfoDB tmpDB = (AppInfoDB)WinAptLib.ReadFromFile(typeof(AppInfoDB), newFile);

            foreach (AppInfoBase item in tmpDB.Items)
            {
                myAppDB.Add(item);
            }
        }
Ejemplo n.º 6
0
 public void LoadDB(string fileName)
 {
     myAppDB = (AppInfoDB)WinAptLib.ReadFromFile(typeof(AppInfoDB), fileName);
     for (int i = 0; i < myAppDB.Items.Count; i++)
     {
         ((AppInfoBase)myAppDB.Items[i]).setIndex(i);
     }
     myAppDB.SetIndex(myAppDB.Items.Count);
 }
Ejemplo n.º 7
0
 public override void UpdateData()
 {
     content = WinAptLib.getPageContent(this.mainPageUrl);
     Parser("");
     Console.WriteLine("Get {0} pages.", pageUrls.Length);
     foreach (string url in this.pageUrls)
     {
         Console.WriteLine("Parsing page {0}", url);
         content = WinAptLib.getPageContent(url);
         Parser(content);
     }
 }
Ejemplo n.º 8
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            //
            //TODO: update db file
            //
            string curDB = WinAptLib.ConfigPath + "appinfodb_" + cbDbs.Text + ".xml";

            if (!File.Exists(curDB))
            {
                //currently there is no such DB file, update DB now?
                string message = MainForm.LocRM.GetString("strConfigFormDownload");
                // Need Update DB
                string            caption = MainForm.LocRM.GetString("strConfigFormMessageTitle");
                MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                DialogResult      result;
                // Displays the MessageBox.
                result = MessageBox.Show(message, caption, buttons);
                if (result == DialogResult.No)
                {
                    // restore value
                    cbDbs.Text  = MainForm.myCmdMgr.Config.local;
                    txtUrl.Text = MainForm.myCmdMgr.Config.updateUrl;
                    return;
                }
                else
                {
                    btnOK.Enabled = false;
                    MainForm.myCmdMgr.Config.local     = cbDbs.Text;
                    MainForm.myCmdMgr.Config.updateUrl = txtUrl.Text;
                    MainForm.myCmdMgr.Config.usingDB   = WinAptLib.ConfigPath + "appinfodb_" + cbDbs.Text + ".xml";
                    //download db;
                    fmMain.UpdateDB(true);
                    btnOK.Enabled = true;
                }
            }
            //nothing change, just return;
            if (cbDbs.Text == MainForm.myCmdMgr.Config.local)
            {
                return;
            }
            else
            {
                MainForm.myCmdMgr.Config.local     = cbDbs.Text;
                MainForm.myCmdMgr.Config.updateUrl = txtUrl.Text;
                MainForm.myCmdMgr.Config.usingDB   = WinAptLib.ConfigPath + "appinfodb_" + cbDbs.Text + ".xml";
                WinAptLib.WriteToFile(MainForm.myCmdMgr.Config, MainForm.configFile);
                fmMain.UpdateDB(false);
            }
        }
Ejemplo n.º 9
0
        public void UpdateDB(bool isDownload)
        {
            if (isDownload)
            {
                btnUpdate.Enabled = false;
                UpdateForm upForm = new UpdateForm(myCmdMgr.Config.updateUrl);
                this.Enabled = false;
                upForm.ShowDialog();
                this.Enabled = true;
            }
            string fileName = myCmdMgr.Config.usingDB;
            string content  = WinAptLib.GetAppInfoContent(fileName);

            if (content == "")
            {
                return;
            }
            myCmdMgr.UpdateAppDB(content);
            updateLvApp();
        }
Ejemplo n.º 10
0
 public void Execute()
 {
     for (int i = 0; i < cmdMgr.SelectItems.Count; i++)
     {
         if (_stop)
         {
             break;
         }
         //We are downloading {0}/{1}
         string format = MainForm.LocRM.GetString("strExecuteFormDownloading");
         string newStr = string.Format(format, i, cmdMgr.SelectItems.Count);
         UpdateLabel(newStr);
         AppInfoBase it    = (AppInfoBase)cmdMgr.InfoDB.Items[(int)cmdMgr.SelectItems[i]];
         string      fname = cmdMgr.GetFilePath((int)cmdMgr.SelectItems[i]);
         string      url   = it.url;
         if (ExecuteCmd(fname, url))
         {
             cmdMgr.Config.Items.Add(cmdMgr.InfoDB.Items[(int)cmdMgr.SelectItems[i]]);
         }
     }
     for (int i = 0; i < cmdMgr.DelectItems.Count; i++)
     {
         if (_stop)
         {
             break;
         }
         //Deleting files.
         UpdateLabel(MainForm.LocRM.GetString("strExecuteFormDeleting"));
         string cmd = cmdMgr.GetFilePath((int)cmdMgr.DelectItems[i]);
         //no exception if file doesnot exists.
         File.Delete(cmd);
         cmdMgr.Config.Items.Remove(cmdMgr.InfoDB.Items[(int)cmdMgr.DelectItems[i]]);
     }
     //Done.
     UpdateText(MainForm.LocRM.GetString("strExecuteFormDone"));
     CancalChange(_stop);
     WinAptLib.WriteToFile(cmdMgr.Config, MainForm.configFile);
     _stop = true;
     SetOKEnable();
 }
Ejemplo n.º 11
0
 public void SaveDB(string fileName)
 {
     WinAptLib.WriteToFile(myAppDB, fileName);
 }