Example #1
0
        public MainWindow()
        {
            // Check if another instance is already running
            Process curProc = Process.GetCurrentProcess();
            Process[] procs = Process.GetProcesses();
            foreach (Process proc in procs) {
                if (curProc.Id != proc.Id) {
                    if (curProc.ProcessName == proc.ProcessName) {
                        MessageBox.Show("SlickUpdater is already running!");
                        Application.Current.Shutdown();
                    }
                }
            }

            if (util.checkDependencies() == false)
            {
                //MessageBoxResult result =
                   MessageBox.Show(
                    "Theres missions .dll's from the slickupdater install folder, please make sure you downloaded the correct version on GitHub and all the required dll's are in the installation folder",
                    "Dun Goofed", MessageBoxButton.OK);

                Process.GetCurrentProcess().Kill();
            }

            string rawSlickJson = String.Empty;

            logIt.add("Starting app");

            //Check Command Line args
            var args = Environment.GetCommandLineArgs();
            for (int i = 0; i < args.Length; i++)
            {
                if (args[i] == "-override")
                {
                    try
                    {
                        rawSlickJson = downloader.webRead(args[i + 1]);
                    }
                    catch (Exception e)
                    {
                        logIt.add("Could not override masterfile: " + e);
                    }
                }
            }
            if (rawSlickJson == String.Empty)
            {
                try
                {
#if DEBUG
                //local debug server for testing
                rawSlickJson = downloader.webRead("http://localhost/slickversion.json");
#else
                    //Default master file location hosted on Project Awesome servers
                    rawSlickJson = downloader.webRead("http://arma.projectawesome.net/beta/repo/slickupdater/slickversion.json");
                }
                catch (Exception ex)
                {
                    logIt.add("Error while downloading slickversion.json trying backup server:\n" + ex.ToString());
                }
                if (String.IsNullOrEmpty(rawSlickJson))
                {
                    try
                    {
                        //Backup master file hosted on GitHub servers
                        rawSlickJson =
                            downloader.webRead(
                                "https://gist.githubusercontent.com/wigumen/015cb44774c6320cf901/raw/6a5f22437997c6c120a1b15beaabdb3ade3be06a/slickversion.json");
                    }
                    catch (Exception ex)
                    {
                        logIt.add("Error while trying to reach backup server going offline mode:\n" + ex.ToString());
                    }
                }
            }

            if (!String.IsNullOrEmpty(rawSlickJson))
            {
                Slickversion = JsonConvert.DeserializeObject<versionfile>(rawSlickJson);
            }
            else
            {
                // the Slickversion file couldn't be downloaded, create it ourselves.
                // Note: this means the data displayed in the app is not correct
                Slickversion = new versionfile();
            }
#endif
            InitializeComponent();
            //First launch message!
            if (Settings.Default.firstLaunch)
            {
                MessageBox.Show(
                    "Hello! This seems to be the first time you launch SlickUpdater so make sure your arma 3 and ts3 path is set correctly in options. Have a nice day!",
                    "Welcome");
                //Note to myself: I actualy set firstLaunch to false in initProps
            }
            LogThread = new logIt();
            repoHide();
            var fs = new FileStream("localversion", FileMode.Create, FileAccess.Write);
            var sw = new StreamWriter(fs);
            sw.WriteLine(SlickVersion);
            sw.Close();

            //Timer callback stuff for clock

            AutoUpdate Update = new AutoUpdate();
            if (Update.exupdate == true)
            {
                Update.CheckAvailableUpdates(SlickVersion, Slickversion.version);
            }
            else
            {
                if (!String.IsNullOrEmpty(Slickversion.version) && !String.IsNullOrEmpty(SlickVersion) &&
                    (Slickversion.version != SlickVersion))
                {
                    MessageBoxResult result =
                        MessageBox.Show(
                            "There seems to be a new version of slickupdater available, do you wanna update it it?",
                            "New Update", MessageBoxButton.YesNo);
                    switch (result)
                    {
                        case MessageBoxResult.Yes:
                            Process.Start("SlickAutoUpdate.exe");
                            Process.GetCurrentProcess().Kill();
                            break;
                        case MessageBoxResult.No:
                            break;
                    }
                }
            }

            initRepos();
            // Initialize Update Worker
            Worker = new BackgroundWorker();
            Worker.DoWork += worker_DoWork;
            Worker.ProgressChanged += worker_ProgressChanged;
            Worker.WorkerReportsProgress = true;
            Worker.RunWorkerCompleted += worker_RunWorkerCompleted;

            //init checkWorker
            CheckWorker = new BackgroundWorker();
            CheckWorker.DoWork += checkWorker_DoWork;
            CheckWorker.ProgressChanged += checkWorker_ProgressChanged;
            CheckWorker.WorkerReportsProgress = true;
            CheckWorker.RunWorkerCompleted += checkWorker_RunWorkerCompleted;

            //reddit worker
            RedditWorker = new BackgroundWorker();
            RedditWorker.DoWork += redditWorker_DoWork;
            RedditWorker.RunWorkerCompleted += redditworker_Done;

            //Init timer
            timer = new DispatcherTimer();
            timer.Tick += updateTime;
            timer.Interval = new TimeSpan(0, 0, 10);
            timer.Start();

            WindowManager.SetWnd(this);

            a3DirText.Text = regcheck.arma3RegCheck();
            a2DirText.Text = regcheck.arma2RegCheck();
            va2DirText.Text = regcheck.varma2RegCheck();
            ts3DirText.Text = regcheck.ts3RegCheck();

            //Sets modpaths
            if (Settings.Default.ModPathA3 == "")
            {
                A3ModPath.Text = a3DirText.Text;
            }

            if (Settings.Default.ModPathA2 == "")
            {
                A2ModPath.Text = a2DirText.Text;
            }            

            Settings.Default.firstLaunch = false;
            InitProperties();
            logocheck();
            if (Settings.Default.WindowHeight > 0 || Settings.Default.WindowWidth > 0)
            {
                mainWindow.Width = Settings.Default.WindowWidth;
                mainWindow.Height = Settings.Default.WindowHeight;
            }
        }
Example #2
0
        public MainWindow()
        {
            // Check if another instance is already running
            Process curProc = Process.GetCurrentProcess();
            Process[] procs = Process.GetProcesses();
            foreach (Process proc in procs) {
                if (curProc.Id != proc.Id) {
                    if (curProc.ProcessName == proc.ProcessName) {
                        MessageBox.Show("SlickUpdater is already running!");
                        Application.Current.Shutdown();
                    }
                }
            }

            if (util.checkDependencies() == false)
            {
                //MessageBoxResult result =
                   MessageBox.Show(
                    "Theres missions .dll's from the slickupdater install folder, please make sure you downloaded the correct version on GitHub and all the required dll's are in the installation folder",
                    "Dun Goofed", MessageBoxButton.OK);

                Process.GetCurrentProcess().Kill();
            }

            string rawSlickJson = String.Empty;

            logIt.add("Starting app");

            //Check Command Line args
            var args = Environment.GetCommandLineArgs();
            for (int i = 0; i < args.Length; i++)
            {
                if (args[i] == "-override")
                {
                    try
                    {
                        rawSlickJson = downloader.webRead(args[i + 1]);
                    }
                    catch (Exception e)
                    {
                        logIt.add("Could not override masterfile: " + e);
                    }
                }
            }
            if (rawSlickJson == String.Empty)
            {
                try
                {
            #if DEBUG
                //local debug server for testing
                rawSlickJson = downloader.webRead("http://localhost/slickversion.json");
            #else
                    //Default master file location hosted on Project Awesome servers
                    rawSlickJson = downloader.webRead("http://arma.projectawesome.net/beta/repo/slickupdater/slickversion.json");
                }
                catch (Exception ex)
                {
                    logIt.add("Error while downloading slickversion.json trying backup server:\n" + ex.ToString());
                }
                if (String.IsNullOrEmpty(rawSlickJson))
                {
                    try
                    {
                        //Backup master file hosted on GitHub servers
                        rawSlickJson =
                            downloader.webRead(
                                "https://gist.githubusercontent.com/wigumen/015cb44774c6320cf901/raw/6a5f22437997c6c120a1b15beaabdb3ade3be06a/slickversion.json");
                    }
                    catch (Exception ex)
                    {
                        logIt.add("Error while trying to reach backup server going offline mode:\n" + ex.ToString());
                    }
                }
            }

            if (!String.IsNullOrEmpty(rawSlickJson))
            {
                Slickversion = JsonConvert.DeserializeObject<versionfile>(rawSlickJson);
            }
            else
            {
                // the Slickversion file couldn't be downloaded, create it ourselves.
                // Note: this means the data displayed in the app is not correct
                Slickversion = new versionfile();
            }
            #endif
            InitializeComponent();
            //First launch message!
            if (Settings.Default.firstLaunch)
            {
                MessageBox.Show(
                    "Hello! This seems to be the first time you launch SlickUpdater so make sure your arma 3 and ts3 path is set correctly in options. Have a nice day!",
                    "Welcome");
                //Note to myself: I actualy set firstLaunch to false in initProps
            }
            LogThread = new logIt();
            repoHide();
            var fs = new FileStream("localversion", FileMode.Create, FileAccess.Write);
            var sw = new StreamWriter(fs);
            sw.WriteLine(SlickVersion);
            sw.Close();

            //Timer callback stuff for clock

            AutoUpdate Update = new AutoUpdate();
            if (Update.exupdate == true)
            {
                Update.CheckAvailableUpdates(SlickVersion, Slickversion.version);
            }
            else
            {
                if (!String.IsNullOrEmpty(Slickversion.version) && !String.IsNullOrEmpty(SlickVersion) &&
                    (Slickversion.version != SlickVersion))
                {
                    MessageBoxResult result =
                        MessageBox.Show(
                            "There seems to be a new version of slickupdater available, do you wanna update it it?",
                            "New Update", MessageBoxButton.YesNo);
                    switch (result)
                    {
                        case MessageBoxResult.Yes:
                            Process.Start("SlickAutoUpdate.exe");
                            Process.GetCurrentProcess().Kill();
                            break;
                        case MessageBoxResult.No:
                            break;
                    }
                }
            }

            initRepos();
            // Initialize Update Worker
            Worker = new BackgroundWorker();
            Worker.DoWork += worker_DoWork;
            Worker.ProgressChanged += worker_ProgressChanged;
            Worker.WorkerReportsProgress = true;
            Worker.RunWorkerCompleted += worker_RunWorkerCompleted;

            //init checkWorker
            CheckWorker = new BackgroundWorker();
            CheckWorker.DoWork += checkWorker_DoWork;
            CheckWorker.ProgressChanged += checkWorker_ProgressChanged;
            CheckWorker.WorkerReportsProgress = true;
            CheckWorker.RunWorkerCompleted += checkWorker_RunWorkerCompleted;

            //reddit worker
            RedditWorker = new BackgroundWorker();
            RedditWorker.DoWork += redditWorker_DoWork;
            RedditWorker.RunWorkerCompleted += redditworker_Done;

            //Init timer
            timer = new DispatcherTimer();
            timer.Tick += updateTime;
            timer.Interval = new TimeSpan(0, 0, 10);
            timer.Start();

            WindowManager.SetWnd(this);

            a3DirText.Text = regcheck.arma3RegCheck();
            a2DirText.Text = regcheck.arma2RegCheck();
            va2DirText.Text = regcheck.varma2RegCheck();
            ts3DirText.Text = regcheck.ts3RegCheck();

            //Sets modpaths
            if (Settings.Default.ModPathA3 == "")
            {
                A3ModPath.Text = a3DirText.Text;
            }

            if (Settings.Default.ModPathA2 == "")
            {
                A2ModPath.Text = a2DirText.Text;
            }

            Settings.Default.firstLaunch = false;
            InitProperties();
            logocheck();
            if (Settings.Default.WindowHeight > 0 || Settings.Default.WindowWidth > 0)
            {
                mainWindow.Width = Settings.Default.WindowWidth;
                mainWindow.Height = Settings.Default.WindowHeight;
            }
        }