Beispiel #1
0
        private bool LoadConfig()
        {
            String path     = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            String filename = path + "\\" + "WOSUploader.xml";

            if (!new FileInfo(filename).Exists)
            {
                return(false);
            }

            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(filename);

                XPathNavigator nav = doc.CreateNavigator();

                XPathNodeIterator iter;
                iter = nav.Select("//WOSUploader/Player");
                while (iter.MoveNext())
                {
                    XmlElement element = iter.Current.UnderlyingObject as XmlElement;

                    WOSPlayer player = new WOSPlayer();
                    player.PlayerName  = iter.Current.Evaluate("string(@name)") as String;
                    player.WurmDir     = iter.Current.Evaluate("string(@wurmdir)") as String;
                    player.WOSUser     = iter.Current.Evaluate("string(WurmOnlineSkillCompare/@username)") as String;
                    player.WOSPassword = iter.Current.Evaluate("string(WurmOnlineSkillCompare/@password)") as String;
                    if (player.WOSUser == null || player.WOSUser.Length == 0)
                    {
                        player.WOSUser = player.PlayerName;
                    }

                    AddLog(String.Format("Configured player {0} in {1}, using WOS user {2}\n", player.PlayerName, player.WurmDir, player.WOSUser));
                    this.players.Add(player);
                }
            }
            catch (Exception e)
            {
                this.players.Clear();
                AddLog(e.ToString() + "\n");
                return(false);
            }

            if (players.Count == 1)
            {
                Username.Text = players[0].WOSUser;
                Password.Text = players[0].WOSPassword;
            }
            else if (players.Count > 1)
            {
                Username.Enabled = false;
            }

            return(true);
        }
Beispiel #2
0
        void watcher_Changed(object sender, FileSystemEventArgs e)
        {
            System.Diagnostics.Debug.WriteLine("File changed: " + e.FullPath);
            trayIcon.ShowBalloonTip(2000, "New skill dump", String.Format("Uploading skill dump {0}", e.Name), ToolTipIcon.Info);
            try
            {
                String    username = Username.Text;
                String    password = Password.Text;
                WOSPlayer player   = (sender as SkillsWatcher).Player as WOSPlayer;
                if (player != null && player.WOSUser != null && player.WOSUser.Length > 0)
                {
                    username = player.WOSUser;
                }
                if (player != null && player.WOSPassword != null && player.WOSPassword.Length > 0)
                {
                    password = player.WOSPassword;
                }

                Uploader uploader = new Uploader(username, password);
                if (uploader.Login())
                {
                    uploader.Upload(e.FullPath);
                    trayIcon.ShowBalloonTip(2000, "New skill dump", String.Format("Uploaded skill dump {0}", e.Name), ToolTipIcon.Info);
                    AddLog(String.Format("Uploaded skill dump {0}\n", e.Name));
                }
                else
                {
                    trayIcon.ShowBalloonTip(2000, "Login failed", "Invalid username or password", ToolTipIcon.Error);
                    AddLog("Login failed. Invalid username or password\n");
                }
            }
            catch (Exception ex)
            {
                trayIcon.ShowBalloonTip(5000, ex.Message, ex.ToString(), ToolTipIcon.Error);
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                AddLog(ex.ToString() + "\n");
            }
        }
Beispiel #3
0
        private bool LoadConfig()
        {
            String path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            String filename = path + "\\" + "WOSUploader.xml";

            if (!new FileInfo(filename).Exists)
                return false;

            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(filename);

                XPathNavigator nav = doc.CreateNavigator();

                XPathNodeIterator iter;
                iter = nav.Select("//WOSUploader/Player");
                while (iter.MoveNext())
                {
                    XmlElement element = iter.Current.UnderlyingObject as XmlElement;

                    WOSPlayer player = new WOSPlayer();
                    player.PlayerName = iter.Current.Evaluate("string(@name)") as String;
                    player.WurmDir = iter.Current.Evaluate("string(@wurmdir)") as String;
                    player.WOSUser = iter.Current.Evaluate("string(WurmOnlineSkillCompare/@username)") as String;
                    player.WOSPassword = iter.Current.Evaluate("string(WurmOnlineSkillCompare/@password)") as String;
                    if (player.WOSUser == null || player.WOSUser.Length == 0)
                        player.WOSUser = player.PlayerName;

                    AddLog(String.Format("Configured player {0} in {1}, using WOS user {2}\n", player.PlayerName, player.WurmDir, player.WOSUser));
                    this.players.Add(player);
                }
            }
            catch (Exception e)
            {
                this.players.Clear();
                AddLog(e.ToString() + "\n");
                return false;
            }

            if (players.Count == 1)
            {
                Username.Text = players[0].WOSUser;
                Password.Text = players[0].WOSPassword;
            }
            else if (players.Count > 1)
            {
                Username.Enabled = false;
            }

            return true;
        }