Esempio n. 1
0
    /// <summary>
    /// Uploads the file.
    /// </summary>
    public static void UploadFile()
    {
        DebugLevelController.Log("Path: " + FilePath, 1);
        DebugLevelController.Log("Username: "******"Pass: "******"Host: ftp://" + FTPHost, 1);

        //end uploading

        /*t2_ = new Thread(UploadThread);
         * if (!t2_.IsAlive)
         *  t2_.Start();*/
        StaticCoroutine.Start(UploadThread());

        EditorLogGenerator.GenerateLog("Upload started");
        shouldCheck = true;

        Uri uri2 = new Uri("ftp://" + FTPHost + "version.thln");

        client2.Credentials          = new System.Net.NetworkCredential(FTPUserName, FTPPassword);
        client2.UploadFileCompleted += new UploadFileCompletedEventHandler(OnFileUploadCompleted2);
        client2.UploadFileAsync(uri2, "STOR", Application.dataPath + "/../TheLauncher/version/version.thln");
        EditorLogGenerator.GenerateLog("Version File Upload Started");

        Uri uri3 = new Uri("ftp://" + FTPHost + "v.thln");

        client3.Credentials          = new System.Net.NetworkCredential(FTPUserName, FTPPassword);
        client3.UploadDataCompleted += new UploadDataCompletedEventHandler(OnFileUploadCompleted3);
        byte[] bytes3 = File.ReadAllBytes(Application.dataPath + "/../TheLauncher/version/v.thln");
        client3.UploadDataAsync(uri3, "STOR", bytes3);
        EditorLogGenerator.GenerateLog("File List Upload Started");
    }
Esempio n. 2
0
    public static IEnumerator UploadThread()
    {
        yield return(null);

        t2_ = new Thread(() =>
        {
            DebugLevelController.Log("--Upload Thread Started", 1);
            FtpWebRequest ftpClient = (FtpWebRequest)FtpWebRequest.Create("ftp://" + FTPHost + new FileInfo(FilePath).Name);
            ftpClient.Credentials   = new System.Net.NetworkCredential(FTPUserName, FTPPassword);
            ftpClient.Method        = System.Net.WebRequestMethods.Ftp.UploadFile;
            //ftpClient.EnableSsl = true;
            ftpClient.UseBinary = true;
            ftpClient.KeepAlive = true;
            DebugLevelController.Log("--FTP Client Created", 1);
            System.IO.FileInfo fi   = new System.IO.FileInfo(FilePath);
            ftpClient.ContentLength = fi.Length;
            byte[] buffer           = new byte[4097];
            int bytes               = 0;
            long total_bytes        = (long)fi.Length;
            System.IO.FileStream fs = fi.OpenRead();
            System.IO.Stream rs     = ftpClient.GetRequestStream();
            long fileLength         = new System.IO.FileInfo(FilePath).Length;
            while (total_bytes > 0)
            {
                if (abortThreadOnNextTry)
                {
                    return;
                }
                bytes = fs.Read(buffer, 0, buffer.Length);
                rs.Write(buffer, 0, bytes);
                total_bytes  = total_bytes - bytes;
                UploadStatus = "Upload Progress: " + GetBytesReadable(fileLength - total_bytes) + "/" + GetBytesReadable(fileLength);
                //yield return new WaitForEndOfFrame();
            }
            //fs.Flush();
            fs.Close();
            rs.Close();
            FtpWebResponse uploadResponse = (FtpWebResponse)ftpClient.GetResponse();
            if (total_bytes == 0)
            {
                UploadStatus = "Upload Done!";
            }
            else
            {
                UploadStatus = uploadResponse.StatusDescription;
            }
            uploadResponse.Close();
        });
        if (!t2_.IsAlive)
        {
            t2_.Start();
        }
    }
Esempio n. 3
0
    /// <summary>
    /// Generates the version file.
    /// </summary>
    /// <param name="ver">Version.</param>
    public static void GenerateVersionFile(string ver)
    {
        string filePath = Application.dataPath + "/../TheLauncher/version/version.thln";

        try
        {
            StreamWriter writer = new StreamWriter(filePath, false);
            writer.WriteLine(ver);
            writer.Close();
        }
        catch (DirectoryNotFoundException)
        {
            Debug.LogWarning("VERSION FILE DOES NOT EXIST! Attempting to create...");
            System.IO.Directory.CreateDirectory(Application.dataPath + "/../TheLauncher/version/version.thln");
            DebugLevelController.Log("Version File Created");
            GenerateVersionFile(ver);
        }
    }
Esempio n. 4
0
    /// <summary>
    /// Compresses the file.
    /// </summary>
    public static void CompressFile(string sDir, string sRelativePath, GZipStream zipStream)
    {
        //Compress file name
        DebugLevelController.Log("Compressing File Name: " + sRelativePath, 0);
        char[] chars = sRelativePath.ToCharArray();
        zipStream.Write(BitConverter.GetBytes(chars.Length), 0, sizeof(int));
        Compress.compressStatus = "File: " + sRelativePath;
        foreach (char c in chars)
        {
            zipStream.Write(BitConverter.GetBytes(c), 0, sizeof(char));
        }
        //Compress file content

        /* byte[] bytes = File.ReadAllBytes(Path.Combine(sDir, sRelativePath));
         * zipStream.Write(BitConverter.GetBytes(bytes.Length), 0, sizeof(int));
         * zipStream.Write(bytes, 0, bytes.Length);
         * strm = zipStream;*/

        FileStream fsSource = new FileStream(Path.Combine(sDir, sRelativePath), FileMode.Open, FileAccess.Read);

        byte[] bytes = new byte[fsSource.Length];
        DebugLevelController.Log("Reading Bytes:" + bytes.Length + " File:" + sRelativePath, 2);
        int numBytesToRead = (int)fsSource.Length;
        int numBytesRead   = 0;

        while (numBytesToRead > 0)
        {
            int n = fsSource.Read(bytes, numBytesRead, numBytesToRead);
            if (n == 0)
            {
                break;
            }

            numBytesRead   += n;
            numBytesToRead -= n;
            DebugLevelController.Log("Reading Bytes:" + bytes.Length + " File:" + sRelativePath, 2);
        }
        numBytesToRead = bytes.Length;

        zipStream.Write(BitConverter.GetBytes(bytes.Length), 0, sizeof(int));
        zipStream.Write(bytes, 0, numBytesToRead);
        strm = zipStream;
    }
Esempio n. 5
0
    /// <summary>
    /// Generates log for uploader default log file which should be located in /LauncherLogs/log.txt
    /// </summary>
    /// <param name="log">The Log string.</param>
    public static void GenerateLog(string log)
    {
        string wholeLog = "-" + Application.companyName + "-version: " + Application.unityVersion.ToString() + "-product name:" + Application.productName + "-" + log + " |Time: " + System.DateTime.Now.ToLongTimeString() + " " + System.DateTime.Now.ToLongDateString();
        string filePath = Application.dataPath + "/LauncherLogs/log.txt";

        try
        {
            StreamWriter writer = new StreamWriter(filePath, true);
            writer.WriteLine(wholeLog);
            writer.Close();
        }
        catch (DirectoryNotFoundException)
        {
            Debug.LogWarning("LOG FILE DOES NOT EXIST! Attempting to create...");
            System.IO.Directory.CreateDirectory(Application.dataPath + "/LauncherLogs/");
            DebugLevelController.Log("Log Folder Created");
            GenerateLog(wholeLog);
        }
        AssetDatabase.ImportAsset("Assets/LauncherLogs/", ImportAssetOptions.ForceUpdate);
        AssetDatabase.Refresh();
    }
Esempio n. 6
0
    void OnGUI()
    {
        window   = (TheLauncher)EditorWindow.GetWindow(typeof(TheLauncher), false, null, false);
        GUI.skin = guiSkin;
        tex      = new Texture2D(1, 1, TextureFormat.RGBA32, false);
        tex.SetPixel(0, 0, new Color(0f, 0.41176f, 0.53333f));
        tex.Apply();
        boxback.normal.background          = tex;
        titleStyle.fontSize                = 20;
        titleStyle.normal.textColor        = Color.white;
        smallButtonStyle.normal.background = tex;
        smallButtonStyle.padding           = new RectOffset(5, 5, 5, 5);
        smallButtonStyle.normal.textColor  = Color.white;
        smallButtonStyle.margin            = new RectOffset(5, 5, 5, 5);
        smallButtonStyle.alignment         = TextAnchor.MiddleCenter;
        tex2 = new Texture2D(1, 1, TextureFormat.RGBA32, false);
        tex2.SetPixel(0, 0, new Color(0f, 0.71176f, 0.83333f));
        tex2.Apply();
        smallButtonStyle.hover.background = tex2;

        //Background 1
        tex = new Texture2D(1, 1, TextureFormat.RGBA32, false);
        tex.SetPixel(0, 0, new Color(0f, 0.20392f, 0.25882f));
        tex.Apply();
        GUI.DrawTexture(new Rect(0, 0, maxSize.x, maxSize.y), tex, ScaleMode.StretchToFill);
        //End Background

        //Horizontal Box: Set version
        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        GUILayout.Label("Set Version (as string): ");
        Compress.LastVersion = GUILayout.TextField(Compress.LastVersion);
        if (GUILayout.Button("Settings", smallButtonStyle))
        {
            showSettings = true;
        }
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();
        //Horizontal Box

        //Horizontal Box: Settings
        if (showSettings)
        {
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            GUILayout.Label("Settings", titleStyle);
            if (GUILayout.Button("Close Settings", smallButtonStyle))
            {
                showSettings = false;
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Set No Log", smallButtonStyle))
            {
                DebugLevelController.DebugLogLevel = -1;
                Debug.Log("No Log");
            }
            if (GUILayout.Button("Set Log Level To: User", smallButtonStyle))
            {
                DebugLevelController.DebugLogLevel = 0;
                Debug.Log("User Level Log");
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Set Log Level To: Developer", smallButtonStyle))
            {
                DebugLevelController.DebugLogLevel = 1;
                Debug.Log("Developer Level Log");
            }
            if (GUILayout.Button("Set Log Level To: Hacker", smallButtonStyle))
            {
                DebugLevelController.DebugLogLevel = 2;
                Debug.Log("Hacker Level Log");
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
        }
        //Horizontal Box

        //Horizontal Box: Select Build
        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        GUILayout.Label("\nSelect your build", titleStyle);
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();
        //Horizontal Box

        //Horizontal Box: Subtitle
        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        GUILayout.Label("Must contain only build files and nothing else");
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();
        //Horizontal Box

        if (GUILayout.Button("Select Build Folder", guiSkin.button))
        {
            SelectBuildFolder();
        }

        //Horizontal Box: Compress and upload
        GUILayout.BeginHorizontal();
        GUILayout.Box("Folder to compress: " + Compress.pathToCompress);
        GUILayout.EndHorizontal();

        if (!String.IsNullOrEmpty(Compress.pathToCompress))
        {
            if (String.IsNullOrEmpty(Compress.compressStatus))
            {
                if (GUILayout.Button("Compress"))
                {
                    bool should = EditorUtility.DisplayDialog(
                        "Compress folder",
                        "Please be aware that if you start the copmression and do some changes to your scripts and recompile, the thread will halt and unity may become unresponsive. \n" +
                        "\n The folder |  " + Compress.pathToCompress + "  | is about to be compressed and put in Project Folder/The Launcher/. " +
                        "\nDo you want to continue?",
                        "Yes, compress!",
                        "No, go back"
                        );
                    if (should)
                    {
                        CompressBuild();
                        DebugLevelController.Log("Compression Started");
                        //DebugLevelController.Log ("Compression Status:" + Compress.compressStatus);
                        FilePath = Compress.pathToUpload;
                        EditorLogGenerator.GenerateLog("Compression Started");
                        Uploader.UploadStatus = null;
                    }
                }
            }
            GUILayout.BeginHorizontal();
            GUILayout.Box("Compression Status (" + Compress.compressCount + "/" + Compress.totalFiles + ");" + Compress.compressStatus);
            GUILayout.EndHorizontal();
        }

        if (!String.IsNullOrEmpty(Compress.compressStatus))
        {
            if (GUILayout.Button("Stop Compression Thread"))
            {
                bool should = EditorUtility.DisplayDialog(
                    "Compress folder",
                    "The Launcher will attempt to stop the compression thread right now." +
                    "\nDo you want to continue?",
                    "Yes, stop!",
                    "No, go back"
                    );
                if (should)
                {
                    CompressHelper.abortThreadOnNextTry = true;
                    DebugLevelController.Log("Compression Stopped");
                    FilePath = Compress.pathToUpload;
                    EditorLogGenerator.GenerateLog("Compression Stopped");
                    Uploader.UploadStatus   = null;
                    Compress.compressStatus = null;
                }
            }
        }

        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        GUILayout.Label("\n---------------------------------------\n");
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();

        //Vertical Box: FTP seciton
        GUILayout.BeginVertical(boxback);
        //Horizontal Box: FTP Upload
        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        GUILayout.Label("\nUpload your build\n", titleStyle);
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();
        //Horizontal Box


        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        GUILayout.Label("FTP Host:");
        FTPHost = GUILayout.TextField(FTPHost);
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        GUILayout.Label("FTP Username:"******"FTP Password:"******"Do not include the 'ftp://' part and should include the folder you wish to upload your game. \nEg. test.com/mygame/download/");
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();

        if (!String.IsNullOrEmpty(FilePath))
        {
            GUILayout.BeginHorizontal();
            if (String.IsNullOrEmpty(Uploader.UploadStatus))
            {
                if (GUILayout.Button("UPLOAD"))
                {
                    bool should = EditorUtility.DisplayDialog(
                        "Upload File",
                        FilePath + "  | is about to be uploaded to '" +
                        "\n" + FTPHost
                        + "\n with username: "******"\n with password: "******"Yes, UPLOAD!",
                        "No, go back"
                        );
                    if (should)
                    {
                        Uploader.FTPHost     = FTPHost;
                        Uploader.FTPUserName = FTPUserName;
                        Uploader.FTPPassword = FTPPassword;
                        Uploader.FilePath    = FilePath;
                        Uploader.UploadFile();
                        DebugLevelController.Log("Upload Started");
                        EditorLogGenerator.GenerateLog("Upload Started");
                        should = false;
                    }
                }
            }
            GUILayout.EndHorizontal();
        }
        //Vertical Box

        //Horizontal Box: Infos
        if (!String.IsNullOrEmpty(FilePath))
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label("File to upload: " + FilePath);
            GUILayout.EndHorizontal();
        }
        GUILayout.BeginHorizontal();
        //DebugLevelController.Log (Uploader.client.IsBusy);
        GUILayout.Box(Uploader.UploadStatus);
        GUILayout.EndHorizontal();
        //Horizontal Box
        GUILayout.EndVertical();
        if (!String.IsNullOrEmpty(Uploader.UploadStatus))
        {
            if (Uploader.UploadStatus.Contains("Upload Done"))
            {
                Uploader.UploadStatus = "";
                this.Close();
                EditorUtility.DisplayDialog(
                    "Upload Done!",
                    "File was uploaded to the server. Now the window will be closed.",
                    "OK"
                    );
            }
        }
        if (!String.IsNullOrEmpty(Uploader.UploadStatus))
        {
            if (Uploader.UploadStatus.Contains("Upload Progress"))
            {
                if (GUILayout.Button("Cancel Upload"))
                {
                    Uploader.abortThreadOnNextTry = true;
                    Uploader.shouldCheck          = false;
                    Uploader.UploadStatus         = null;
                    DebugLevelController.Log("Upload Cancelled");
                    EditorLogGenerator.GenerateLog("Upload Cancelled");
                }
            }
        }
    }
Esempio n. 7
0
    public static IEnumerator CompressRoutine(string sInDir, string sOutFile)
    {
        lastDone = false;
        Compress.compressCount  = 0;
        Compress.compressStatus = "Getting Files";
        string[] sFiles  = Directory.GetFiles(sInDir, "*.*", SearchOption.AllDirectories);
        int      iDirLen = sInDir[sInDir.Length - 1] == Path.DirectorySeparatorChar ? sInDir.Length : sInDir.Length + 1;

        Compress.totalFiles = sFiles.Length;
        yield return(null);

        t3_ = new Thread(() =>
        {
            FileStream outFile   = new FileStream(sOutFile, FileMode.Create, FileAccess.Write, FileShare.None, 4096, true);
            GZipStream str       = new GZipStream(outFile, CompressionMode.Compress);
            abortThreadOnNextTry = false;
            foreach (string sFilePath in sFiles)
            {
                lastDone = false;
                Compress.compressCount++;
                string sRelativePath    = sFilePath.Substring(iDirLen);
                Compress.compressStatus = "Compressing..";
                //Compress file name
                DebugLevelController.Log("Compressing File Name: " + sRelativePath);
                char[] chars = sRelativePath.ToCharArray();
                str.Write(BitConverter.GetBytes(chars.Length), 0, sizeof(int));
                Compress.compressStatus = "File: " + sRelativePath;
                foreach (char c in chars)
                {
                    str.Write(BitConverter.GetBytes(c), 0, sizeof(char));
                }
                //Compress file content
                DebugLevelController.Log("Compressing File Content: " + sRelativePath, 1);
                int bufferSize = 500 * 1024; //* 1024; // 100MB
                byte[] buffer  = new byte[bufferSize];
                int bytesRead  = 0;
                long DoneBytes = 0;
                using (FileStream fsSource = new FileStream(Path.Combine(sInDir, sRelativePath), FileMode.Open, FileAccess.Read))
                {
                    DebugLevelController.Log("File Stream Created: " + fsSource.Name, 1);
                    while ((bytesRead = fsSource.Read(buffer, 0, bufferSize)) > 0)
                    {
                        if (abortThreadOnNextTry)
                        {
                            return;
                        }
                        DoneBytes += bufferSize;
                        DebugLevelController.Log("Reading Bytes:" + (DoneBytes) + "/" + fsSource.Length + " File:" + sRelativePath, 2);
                        Compress.compressStatus = ((double)(((DoneBytes) / fsSource.Length) * 100)).ToString() + "%" + " File:" + sRelativePath;
                        str.Write(BitConverter.GetBytes(buffer.Length), 0, sizeof(int));
                        str.Write(buffer, 0, buffer.Length);
                    }
                }
                strm = str;
            }
            lastDone = true;
            if (abortThreadOnNextTry)
            {
                Compress.compressStatus = "Compression Aborted!";
                DebugLevelController.Log("Compression Aborted At:" + DateTime.Now.ToShortTimeString());
                strm.Close();
            }
            else
            {
                Compress.compressStatus = "Compression Done!";
                DebugLevelController.Log("Compression Done At:" + DateTime.Now.ToShortTimeString());
                strm.Close();
            }
        });
        if (!t3_.IsAlive)
        {
            t3_.Start();
        }

        /*while (!lastDone)
         *  yield return null;*/
        yield return(null);

        EditorLogGenerator.GenerateLog("Compression Done At:" + DateTime.Now.ToShortTimeString());
        yield return(null);
    }
Esempio n. 8
0
 /// <summary>
 /// File List upload complete event.
 /// </summary>
 static void OnFileUploadCompleted3(object sender, UploadDataCompletedEventArgs e)
 {
     DebugLevelController.Log("File List Uploaded");
 }
Esempio n. 9
0
 /// <summary>
 /// Version file upload complete event.
 /// </summary>
 static void OnFileUploadCompleted2(object sender, UploadFileCompletedEventArgs e)
 {
     DebugLevelController.Log("Version Uploaded");
 }