public WeeboxSync(){
     core = CoreAbstraction.getCore();
     this.docTypes = core.docTypes; 
     fileSystem = new FicheiroSystemAbstraction();
     dataBase = new DataBaseAbstraction(); 
     bundlesToUpdate = new List<string> ();
 }
        public static void setup()
        {
            ConnectionInfo con = new ConnectionInfo(
                new Utilizador("g10_demo", "demo"),
                "http://photo.weebox.keep.pt/", "http://proxy.uminho.pt/");

            CoreAbstraction core = CoreAbstraction.getCore();

            WeeboxSync wee = new WeeboxSync();
            FicheiroSystemAbstraction abs = new FicheiroSystemAbstraction();
            DataBaseAbstraction ab = new DataBaseAbstraction();
            ab.deleteALl();
            if (Directory.Exists(@"c:\users\fabiim\my documents\my weebox")){
                abs.DeleteRecursiveFolder(@"c:\users\fabiim\my documents\my weebox");
            }
            wee.connection_info = con;
            wee.setDefaultRootFolder();
            Watcher w= new Watcher(ref wee, wee.getRootFolder() + "\\Bundles");
            wee.SetWatcher(ref w);
               w.Disable();
               while (true){
               try{
                   wee.setup();
                   while (true){
                       wee.SynchronizeAll();
                   }
               }
               catch (Exception e){
                   Console.Out.Write("Exception");
                   Console.Out.Write(e);
               }
               }
            try{
                wee.setup();

                while (true){
                    wee.SynchronizeAll();
                }
            }catch (Exception e){
                Console.Out.Write("Exception");
                Console.Out.Write(e);
                Console.Read();

            }
            /*            //wee.getBundleInfo("2BF883C16A5D8C2E827CD47A6EA19028");
            Ficheiro file = new Ficheiro(@"c:\asd.png", true);
            List<Ficheiro> files = new List<Ficheiro>(){ new Ficheiro(@"c:\asd.png", true), new Ficheiro(@"c:\drf.png", true) };
            wee.PutFicheiros("689421950C2542A0A7E09C76E40536C4", files);
            */
            //wee.RemoveFicheiros(
            //            wee.RemoveFicheiros("E37ADFC66E0ECB631998DFB13B34BB63",
            //                                new List<string>()
            //                                    {
                                    //    "1F8FEC6875461D0B5BA6EA7972486F8B",
            //                                        "66BF8E7E5DCAF1D96FEE3EA78D8549CD"
              //                                  });

            Console.ReadLine();
            //            wee.PutFicheiro("", new Ficheiro());

            //con.user
            //con.proxy.ToString();

            //            WeeboxSync weebox = new WeeboxSync();
            //          weebox.connection_info = con;
            //        weebox.setup();
            //            CoreAbstraction core = CoreAbstraction.getCore();
            //            core.SetConnection(con);

            //            core.PutFicheiro("", new Ficheiro());
        }
        private static bool DoSetup()
        {
            ConnectionInfo ci = null;
            Weebox = new WeeboxSync();
            int state = 1;
            bool cont = true;
            FicheiroSystemAbstraction fsa = new FicheiroSystemAbstraction();
            WelcomeScreen ws = new WelcomeScreen ();
            ws.ShowDialog ();
            do {
                /**
                * if dialog results are DialogResult.Retry,
                * show the last form (back button was pressed)
                * if the result is Cancel, setup is to be canceled entirely
                * if the result is OK, follow to the next form, up until download.
                */

                DialogResult result;
                switch (state) {
                    case 1:
                        ci = new ConnectionInfo();
                        ConnectionInfoEditor cie = new ConnectionInfoEditor (ref ci);
                        result = cie.ShowDialog ();
                        if (result == DialogResult.Cancel)
                            return false;
                        if(result == DialogResult.Retry)
                            state = 0; // exit
                        else
                            state++;
                        break;
                    case 2:
                        if(ci == null) {
                            state = 0;
                            break;
                        }
                        Weebox.connection_info = ci;
                        LoginWindow lw = new LoginWindow ( ref Weebox);
                        result = lw.ShowDialog ();
                        if (result == DialogResult.Cancel)
                            return false;
                        if(result == DialogResult.Retry)
                            state--; // back to previous dialog
                        else
                            state++; // next dialog
                        break;
                    case 3:
                        FolderChooser fc = new FolderChooser (ref Weebox);
                        result = fc.ShowDialog ();
                        if (result == DialogResult.Cancel)
                            return false;
                        if (result == DialogResult.Retry)
                            state--; // back to previous dialog
                        else
                            state++; // next dialog
                        break;
                    case 4:
                        //setup successful, go to download
                        SaveRegistryKeys ();
                        DataBaseAbstraction dba = new DataBaseAbstraction ();
                        try
                        {
                            dba.SaveConnectionInfo(Weebox.connection_info);
                        }
                        catch (Exception e) {
                            //eliminar chaves de registo
                            DeleteRegistryKeys();
                            //eliminar pasta root
                            fsa.DeleteRecursiveFolder(Weebox.getRootFolder());
                            MessageBox.Show(
                                "Setup falhou. Por favor inicie novamente a aplicação, verifique os dados inseridos e tente novamente",
                                "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return false;
                        }
                        DownloadWait dw = new DownloadWait (ref Weebox);
                        var res = dw.ShowDialog ();
                        if(res == DialogResult.Cancel) {
                            //eliminar chaves de registo
                            DeleteRegistryKeys();
                            //eliminar pasta root
                            fsa.DeleteRecursiveFolder(Weebox.getRootFolder());
                            MessageBox.Show(
                                "Setup falhou. Por favor inicie novamente a aplicação, verifique os dados inseridos e tente novamente",
                                "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return false;
                        }
                        else if (res == DialogResult.OK) {
                            MessageBox.Show ("O setup foi concluído com sucesso.\nBem-vindo ao mundo Weebox.", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        cont = false;
                        break;

                    case 5:
                        // all tasks done, exit

                        return true;
                    case 0:
                        //Cancel setup and exit application
                        Application.Exit ();
                        return false;
                    default:
                        MessageBox.Show (
                            "Houve um erro no processo de instalação.\n" +
                            "Por favor volte a iniciar a aplicação para concluir o processo,",
                            "Erro",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                        //eliminar chaves de registo
                        DeleteRegistryKeys();
                        //eliminar pasta root
                        fsa.DeleteRecursiveFolder(Weebox.getRootFolder());
                        Application.Exit();
                        break;
                }
            } while (cont);
            //MessageBox.Show ("Setup done!, Now we rock!");
            return true;
        }