Ejemplo n.º 1
0
        /*
         * Construct the form
         */
        public MainForm()
        {
            InitializeComponent();

            if (Properties.Settings.Default.outputPath != "")
            {
                loadFileToolStripMenuItem.Enabled = true;   // Enable file loading if path isn't empty
            }
            ProcessHandler.StartTimer(this);                // Instantiate process timer with MainForm as the parent
            SetLabelStatus(ProcessHandler.ProcessStatus()); // Set the label to the process status
        }
Ejemplo n.º 2
0
        public static DateTime?LastLogWrite;  // Stores the last write time of the log

        public static void LoadSongList(MainForm _parent, string[] _files)
        {
            string outputLog = "output_log.txt";

            string[] files = _files;

            parent = _parent;

            List <Song> songList = new List <Song>();

            if (ProcessHandler.IsProcessRunning())
            {
                MessageBox.Show("Error: Cannot load songs while Audioshield is running.");
                return;
            }

            foreach (string file in files)
            {
                if (Path.GetFileName(file) != outputLog)
                {
                    MessageBox.Show(String.Format("Invalid file: {0}", file));
                    break;
                }

                if (LastLogWrite == File.GetLastWriteTime(file)) // Don't load the same file
                {
                    MessageBox.Show("Error: The songs from this file have already loaded.");
                    break;
                }

                string       line;
                Match        soundcloudMatch, scoreMatch, xmlMatch, artistMatch;
                StreamReader output = new StreamReader(file);

                while ((line = output.ReadLine()) != null)
                {
                    /*soundcloudMatch = Regex.Match(line, @"url:(https://api\.soundcloud\.com/tracks\?q=.+)");
                     *
                     * if (soundcloudMatch.Success)
                     * {
                     *  HandleSoundcloudMatch(parent, soundcloudMatch);
                     *  continue;
                     * }*/

                    scoreMatch = Regex.Match(line, @"setting score (\d+) for song: (.+)");

                    if (scoreMatch.Success)
                    {
                        HandleScoreMatch(parent, scoreMatch, songList);
                        continue;
                    }

                    artistMatch = Regex.Match(line, @"duration:(\d*)\s*artist:(.*)");

                    if (artistMatch.Success)
                    {
                        HandleArtistMatch(parent, artistMatch, songList);
                        continue;
                    }

                    xmlMatch = Regex.Match(line, @"<document><user userid='(.+)' regionid='(.+)' email='' canpostscores='(.+)'></user><modeid modeid='(.+)'></modeid><modename modename='(.+)'></modename><scoreboards songid='(\d+)' modeid='(\d+)'>");

                    if (xmlMatch.Success)
                    {
                        HandleXmlMatch(output, xmlMatch, songList);
                        continue;
                    }
                }

                output.Close();

                if (Song.Count <= 0) // If no songs were loaded notify the user
                {
                    MessageBox.Show(String.Format("Error: No submitted scores were found in path {0}", file));
                    break;
                }

                if (!parent.songBox.Visible)
                {
                    parent.songBox.DisplayMember = "Title";

                    // We may require invoking so use DoUI
                    parent.DoUI(() =>
                    {
                        //parent.label1.Visible = false;
                        parent.songBox.Visible = true;
                    });
                }

                LastLogWrite = File.GetLastWriteTime(file);     // Store the write time of the last loaded file

                string xmlString = SerializeSongData(songList); // serialize the song data to a string
                //Console.WriteLine(xmlString);
                Cursor.Current = Cursors.WaitCursor;
                PostSongData(xmlString); // post the xml to the web server
            }
        }