Exemplo n.º 1
0
    void Start()
    {
        manager = GameObject.FindGameObjectWithTag ( "Manager" );
        startupManager = manager.GetComponent<StartupManager> ();
        socketsManager = manager.GetComponent<SocketsManager> ();
        onlineMusicBrowser = GameObject.FindGameObjectWithTag ( "OnlineMusicBrowser" ).GetComponent <OnlineMusicBrowser>();
        paneManager = manager.GetComponent <PaneManager> ();
        loadingImage = GameObject.FindGameObjectWithTag ( "LoadingImage" ).GetComponent<LoadingImage>();
        currentSlideshowImage = GameObject.FindGameObjectWithTag ( "SlideshowImage" ).GetComponent<GUITexture>();
        currentSong = GameObject.FindGameObjectWithTag ( "CurrentSong" ).GetComponent<GUIText>();

        musicViewerPosition.width = Screen.width;
        musicViewerPosition.height = Screen.height;

        bottomBarPosition = new Rect (( musicViewerPosition.width - 240 ) / 2 , musicViewerPosition.height - 18, 240, 54 );

        optionsWindowRect.x = musicViewerPosition.width/2 - optionsWindowRect.width/2;
        optionsWindowRect.y = musicViewerPosition.height/2 - optionsWindowRect.height/2;

        audioVisualizer = GameObject.FindGameObjectWithTag ("AudioVisualizer").GetComponent<AudioVisualizer> ();

        timemark = GameObject.FindGameObjectWithTag ( "Timemark" ).GetComponent<GUIText> ();
        GameObject.FindGameObjectWithTag ( "TimebarImage" ).guiTexture.pixelInset = new Rect ( -musicViewerPosition.width/2, musicViewerPosition.height/2 - 3, musicViewerPosition.width, 6 );

        LoadSettings ( false );

        centerStyle = new GUIStyle ();
        centerStyle.alignment = TextAnchor.MiddleCenter;

        labelStyle = new GUIStyle ();
        labelStyle.alignment = TextAnchor.MiddleCenter;
        labelStyle.wordWrap = true;

        folderStyle = new GUIStyle ();
        folderStyle.alignment = TextAnchor.MiddleLeft;
        folderStyle.border = new RectOffset ( 6, 6, 4, 4 );
        folderStyle.hover.background = guiSkin.button.hover.background;
        folderStyle.active.background = guiSkin.button.active.background;
        folderStyle.fontSize = 22;

        fileStyle = new GUIStyle ();
        fileStyle.alignment = TextAnchor.MiddleLeft;
        fileStyle.border = new RectOffset ( 6, 6, 6, 4 );
        fileStyle.padding = new RectOffset ( 6, 6, 3, 3 );
        fileStyle.margin = new RectOffset ( 4, 4, 4, 4 );
        fileStyle.hover.background = guiSkin.button.hover.background;
        fileStyle.active.background = guiSkin.button.active.background;
        fileStyle.fontSize = 22;

        fileBrowserFileStyle = new GUIStyle ();
        fileBrowserFileStyle.alignment = TextAnchor.MiddleLeft;

        currentSongStyle = new GUIStyle ();
        currentSongStyle.font = secretCode;
        currentSongStyle.fontSize = 31;

        songStyle = new GUIStyle ();
        songStyle.alignment = TextAnchor.MiddleLeft;
        songStyle.fontSize = 16;

        buttonStyle = new GUIStyle ();
        buttonStyle.fontSize = 22;
        buttonStyle.alignment = TextAnchor.MiddleCenter;
        buttonStyle.border = new RectOffset ( 6, 6, 6, 4 );
        buttonStyle.padding = new RectOffset ( 6, 6, 3, 3 );
        buttonStyle.margin = new RectOffset ( 4, 4, 4, 4 );
        buttonStyle.hover.background = guiSkin.button.hover.background;

        hideGUIStyle = new GUIStyle ();
        hideGUIStyle.normal.background = hideGUINormal;
        hideGUIStyle.hover.background = hideGUIHover;
        hideGUIStyle.onNormal.background = hideGUIOnNormal;
        hideGUIStyle.onHover.background = hideGUIOnHover;

        showVisualizerStyle = new GUIStyle ();
        showVisualizerStyle.normal.background = showAudioVisualizerNormal;
        showVisualizerStyle.hover.background = showAudioVisualizerHover;
        showVisualizerStyle.onNormal.background = showAudioVisualizerOnNormal;
        showVisualizerStyle.onHover.background = showAudioVisualizerOnHover;

        doubleSpeedStyle = new GUIStyle ();
        doubleSpeedStyle.normal.background = audioSpeedDoubleNormal;
        doubleSpeedStyle.hover.background = audioSpeedDoubleHover;
        doubleSpeedStyle.onNormal.background = audioSpeedNormalNormal;
        doubleSpeedStyle.onHover.background = audioSpeedNormalHover;

        halfSpeedStyle = new GUIStyle ();
        halfSpeedStyle.normal.background = audioSpeedHalfNormal;
        halfSpeedStyle.hover.background = audioSpeedHalfHover;
        halfSpeedStyle.onNormal.background = audioSpeedNormalNormal;
        halfSpeedStyle.onHover.background = audioSpeedNormalHover;

        echoStyle = new GUIStyle ();
        echoStyle.normal.background = echoNormal;
        echoStyle.hover.background = echoHover;
        echoStyle.onNormal.background = echoOnNormal;
        echoStyle.onHover.background = echoOnHover;

        InvokeRepeating ( "Refresh", 0, 2 );
        StartCoroutine ( SetArtwork ());
    }
    void Start()
    {
        ServicePointManager.ServerCertificateValidationCallback += delegate ( object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors ) { return true; };

        if ( developmentMode == true )
            UnityEngine.Debug.Log ( "Development Mode is ON" );

        onlineMusicBrowser = GameObject.FindGameObjectWithTag ( "OnlineMusicBrowser" ).GetComponent<OnlineMusicBrowser>();
        musicViewer = GameObject.FindGameObjectWithTag ( "MusicViewer" ).GetComponent<MusicViewer>();
        paneManager = gameObject.GetComponent<PaneManager>();

        if ( Environment.OSVersion.ToString ().Substring ( 0, 4 ) == "Unix" )
        {

            path = mac;
            twoCatStudiosPath = Path.DirectorySeparatorChar + "Users" + Path.DirectorySeparatorChar  + Environment.UserName + Path.DirectorySeparatorChar + "Library" + Path.DirectorySeparatorChar  + "Application Support" + Path.DirectorySeparatorChar + "2Cat Studios" + Path.DirectorySeparatorChar;
            directoryBrowser = "Finder";
        } else
        {

            path = windows;
            twoCatStudiosPath = Environment.GetFolderPath ( Environment.SpecialFolder.CommonApplicationData ) + Path.DirectorySeparatorChar + "2Cat Studios" + Path.DirectorySeparatorChar;
            directoryBrowser = "File Explorer";
        }

        mediaPath = path + "Media" + Path.DirectorySeparatorChar;
        supportPath = path + "Support" + Path.DirectorySeparatorChar;
        downloadedPath = mediaPath + "Downloaded" + Path.DirectorySeparatorChar;
        helpPath = supportPath + Path.DirectorySeparatorChar + "FAQ & Tutorial.txt" + Path.DirectorySeparatorChar;
        slideshowPath = path + "Slideshow" + Path.DirectorySeparatorChar;
        tempPath = supportPath + "Temp" + Path.DirectorySeparatorChar;

        preferences.lastDirectory = mediaPath.Substring ( 0, mediaPath.Length - 1 );

        if ( !Directory.Exists ( twoCatStudiosPath ))
        {

            UnityEngine.Debug.Log ( twoCatStudiosPath + " does not exist!" );
            Directory.CreateDirectory ( twoCatStudiosPath );
        }

        if ( ReadTwoCatSettings () == true )
        {

            if ( WriteTwoCatSettings () == true )
            {

                if ( developmentMode == true )
                {

                    UnityEngine.Debug.Log ( "TwoCat Settings Loaded Successfully" );
                }
            }
        } else {

            if ( WriteTwoCatSettings () != true )
            {

                UnityEngine.Debug.LogError ( "Unable to Write TwoCat Settings!" );
            }
        }

        if ( !Directory.Exists ( mediaPath ))
            Directory.CreateDirectory ( mediaPath );

        if ( !Directory.Exists ( mediaPath + "Albums" ))
            Directory.CreateDirectory ( mediaPath + "Albums" );

        if ( !Directory.Exists ( mediaPath + "Artists" ))
            Directory.CreateDirectory ( mediaPath + "Artists" );

        if ( !Directory.Exists ( mediaPath + "Genres" ))
            Directory.CreateDirectory ( mediaPath + "Genres" );

        if ( !Directory.Exists ( mediaPath + "Playlists" ))
            Directory.CreateDirectory ( mediaPath + "Playlists" );

        if ( !Directory.Exists ( mediaPath + "Downloaded" ))
            Directory.CreateDirectory ( mediaPath + "Downloaded" );

        if ( !Directory.Exists ( supportPath ))
            Directory.CreateDirectory(supportPath );

        if ( !Directory.Exists ( slideshowPath ))
        {

            Directory.CreateDirectory ( slideshowPath );
            File.Copy ( Application.streamingAssetsPath + Path.DirectorySeparatorChar + "UnityMusicPlayerIcon.png", slideshowPath + "UnityMusicPlayerIcon.png", true );
        }

        if ( !File.Exists ( slideshowPath + "UnityMusicPlayerIcon.png" ))
            File.Copy ( Application.streamingAssetsPath + Path.DirectorySeparatorChar + "UnityMusicPlayerIcon.png", slideshowPath + "UnityMusicPlayerIcon.png", true );

        if ( !Directory.Exists ( tempPath ))
        {

            Directory.CreateDirectory ( tempPath );
        } else if ( Directory.GetFiles ( tempPath ).Length > 0 )
        {

            DirectoryInfo tempDirectory = new DirectoryInfo ( tempPath );
            tempDirectory.Delete ( true );

            Directory.CreateDirectory ( tempPath );
        }

        if ( ReadPreferences () == true )
        {

            if ( WritePreferences () == true )
            {

                if ( developmentMode == true )
                {

                    UnityEngine.Debug.Log ( "Universal Settings Loaded Successfully" );
                }
            }
        } else {

            if ( WritePreferences () != true )
            {

                UnityEngine.Debug.LogError ( "Unable to Write Universal Settings!" );
            }
        }

        if ( !Directory.Exists ( preferences.lastDirectory ))
        {

            preferences.lastDirectory = mediaPath.Substring ( 0, mediaPath.Length - 1 );
        }

        if ( !File.Exists ( supportPath + "FAQ & Tutorial.txt" ) || !File.Exists ( supportPath + "ReadMe.txt" ))
        {

            File.Copy ( Application.streamingAssetsPath + Path.DirectorySeparatorChar + "FAQ & Tutorial.txt", supportPath + "FAQ & Tutorial.txt", true );
            File.Copy ( Application.streamingAssetsPath + Path.DirectorySeparatorChar + "ReadMe.txt", supportPath + "ReadMe.txt",true  );

        } else if ( developmentMode == false )
        {

            try
            {

                TextReader faq = File.OpenText ( supportPath + "FAQ & Tutorial.txt" );
                TextReader readme = File.OpenText ( supportPath + "ReadMe.txt" );

                string faqVersion = faq.ReadLine ().Substring ( 17 );
                string readmeVersion = readme.ReadLine ().Substring ( 17 );

                faq.Close ();
                readme.Close ();

                try
                {

                    if (float.Parse(faqVersion, CultureInfo.InvariantCulture.NumberFormat) < float.Parse(runningVersion))
                    {

                        File.Delete(supportPath + "FAQ & Tutorial.txt");
                        File.Copy(Application.streamingAssetsPath + Path.DirectorySeparatorChar + "FAQ & Tutorial.txt", supportPath + "FAQ & Tutorial.txt");
                    }
                    if (float.Parse(readmeVersion, CultureInfo.InvariantCulture.NumberFormat) < float.Parse(runningVersion))
                    {

                        File.Delete(supportPath + "ReadMe.txt");
                        File.Copy(Application.streamingAssetsPath + Path.DirectorySeparatorChar + "ReadMe.txt", supportPath + "ReadMe.txt");
                    }
                }
                catch (Exception e)
                {

                    UnityEngine.Debug.Log ( "Unable to Read FAQ and Tutorial/ReadMe, rewritting, " + e );

                    File.Delete(supportPath + "FAQ & Tutorial.txt");
                    File.Copy(Application.streamingAssetsPath + Path.DirectorySeparatorChar + "FAQ & Tutorial.txt", supportPath + "FAQ & Tutorial.txt");

                    File.Delete(supportPath + "ReadMe.txt");
                    File.Copy(Application.streamingAssetsPath + Path.DirectorySeparatorChar + "ReadMe.txt", supportPath + "ReadMe.txt");
                }
            }
            catch ( ArgumentOutOfRangeException error )
            {

                UnityEngine.Debug.Log ( "FAQ or ReadMe is not formatted properly! " + error );

                File.Delete ( supportPath + "FAQ & Tutorial.txt" );
                File.Copy ( Application.streamingAssetsPath + Path.DirectorySeparatorChar + "FAQ & Tutorial.txt", supportPath + "FAQ & Tutorial.txt" );

                File.Delete ( supportPath + "ReadMe.txt" );
                File.Copy ( Application.streamingAssetsPath + Path.DirectorySeparatorChar + "ReadMe.txt", supportPath + "ReadMe.txt" );
            }
        }

        prefsLocation = supportPath + "Preferences.umpp";

        if ( preferences.checkForUpdate == true || preferences.enableOMB == true )
        {

            Thread internetConnectionsThread = new Thread (() => InternetConnections ( preferences.checkForUpdate, preferences.enableOMB ));
            internetConnectionsThread.Start ();

            if ( preferences.enableOMB == true )
            {

                paneManager.loading = true;
                connectionInformation.text = "Connecting to the OnlineMusicDatabase";
                startTime = Time.realtimeSinceStartup;
                InvokeRepeating ( "CheckStartOnlineMusicBrowser", 0, 0.2F );
            }
        }
    }