예제 #1
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");
        }
예제 #2
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);
        }
예제 #3
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);
            }
        }
예제 #4
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();
 }
예제 #5
0
 public void SaveDB(string fileName)
 {
     WinAptLib.WriteToFile(myAppDB, fileName);
 }