Ejemplo n.º 1
0
        private void RunDownload()
        {
            if (!Directory.Exists(txt_Save.Text + "Unity3D"))
            {
                Directory.CreateDirectory(txt_Save.Text + "Unity3D");
            }

            List <DownloadInfo> list = new List <DownloadInfo>();
            string Extension         = (chb_Unity3d.Checked ? ".unity3d" : "");

            string[] FileList = lib_File.Items.Cast <string>().ToArray();
            string   Url;

            if (rdb_ST.Checked)
            {
                Url = "http://img.wcproject.so-net.tw/assets/469/";
            }
            else if (rdb_SJ.Checked)
            {
                Url = "http://i.wcat.colopl.jp/assets/2018/";
            }
            else if (rdb_SK.Checked)
            {
                Url = "http://i-wcat-colopl-kr.akamaized.net/assets/465/";
            }
            else if (rdb_tennis.Checked)
            {
                Url = "http://i-tennis-colopl-jp.akamaized.net/asset_bundle/";
            }
            else
            {
                Url = txt_URL.Text;
            }

            if (rdb_tennis.Checked && RB_A.Checked)
            {
                Url += "android/0.0.1/";
            }
            else if (rdb_tennis.Checked && RB_I.Checked)
            {
                Url += "ios/0.0.1/";
            }
            else if (!rdb_Custom.Checked && RB_A.Checked)
            {
                Url += "a/";
            }
            else if (!rdb_Custom.Checked && RB_I.Checked)
            {
                Url += "i/";
            }

            SetProgressBarValue(0, PB_TotalFile);
            tbManager.SetProgressValue(0, FileList.Length);
            tbManager.SetProgressState(TaskbarProgressBarState.Normal);

            foreach (string fileName in FileList)
            {
                if (fileName == "" || fileName.Substring(0, 1) == "'" || !fileName.ComparisonFileName())
                {
                    DelListBox(fileName.ToString(), lib_File);
                }
                else
                {
                    string       urlAddress = Url + fileName + Extension + "?r=" + DateTime.Now.ToFileTime().ToString();
                    DownloadInfo info       = new DownloadInfo(urlAddress, txt_Save.Text, this, fileName + ".unity3d");
                    list.Add(info);
                    info.StartDownload();
                }
            }

            list.ForEach(delegate(DownloadInfo item)
            {
                SetToolStripLabelText("下載中 (" + (PB_TotalFile.Value * 100.0 / list.Count).ToString("0.0") + "%)", lab_Status);
                while (!item.IsDone)
                {
                    if (!isWorking)
                    {
                        if (item.WC != null)
                        {
                            item.WC.CancelAsync();
                        }
                        break;
                    }
                    SetLabelText("下載檔案: " + item.FileName, lab_Download);
                    SetLabelText(string.Format("{0} KB / {1} KB", item.KBytesReceived.ToString("0.0"), item.TotalKBytesToReceive.ToString("0.0")), lab_Speed);
                    SetProgressBarValue(item.KBytesReceived, PB_SingleFile);
                    SetProgressBarMaxValue(item.TotalKBytesToReceive, PB_SingleFile);
                    Thread.Sleep(500);
                }
                if (item.IsCancelled)
                {
                    AddListBoxItem(Path.GetFileNameWithoutExtension(item.FileName), lib_Error);
                }
                else if (item.Error != "")
                {
                    AddListBoxItem(Path.GetFileNameWithoutExtension(item.FileName), lib_Error);
                }
                SetProgressBarValue(PB_TotalFile.Value + 1, PB_TotalFile);
                SetToolStripLabelText("錯誤檔案數: " + lib_Error.Items.Count.ToString(), lab_ErrorItem);
                SetToolStripLabelText("已下載數: " + PB_TotalFile.Value, lab_DownItem);
                DelListBox(Path.GetFileNameWithoutExtension(item.FileName), lib_File);
                tbManager.SetProgressValue(PB_TotalFile.Value, FileList.Length);
            });

            list.Clear();
            SetProgressBarValue(0, PB_SingleFile);
            SetProgressBarMaxValue(0, PB_SingleFile);
            SetLabelText("0 KB / 0 KB", lab_Speed);
            if (extFile.Count != 0)
            {
                SetToolStripLabelText("檔案數: " + extFile.Count, lab_Item);
                SetProgressBarValue(0, PB_TotalFile);
                SetProgressBarMaxValue(extFile.Count, PB_TotalFile);

                SetToolStripLabelText("載入資料中", lab_Status);
                assetsManager.LoadFolder(txt_Save.Text + "Unity3D");

                SetToolStripLabelText("解包中", lab_Status);
                Parallel.ForEach(assetsManager.assetsFileList, (item) =>
                {
                    string fileName = Path.GetFileNameWithoutExtension(item.originalPath);
                    if (!extFile.Contains(fileName + ".unity3d"))
                    {
                        return;
                    }

                    bool Export = true;
                    if (TSM_UnPrefab.Checked && TSM_Exclude.Text != "")
                    {
                        foreach (string item2 in TSM_Exclude.Text.Split(new char[] { ',' }))
                        {
                            if (fileName.ToLower().Contains(item2.ToLower()))
                            {
                                Export = false; break;
                            }
                        }
                    }

                    if (Export)
                    {
                        SetToolStripLabelText("解包: " + fileName, lab_Execute);
                        foreach (var item2 in item.m_Objects)
                        {
                            string SavePath = "";
                            ObjectReader OR = new ObjectReader(item.reader, item, item2);
                            switch (OR.type)
                            {
                            case ClassIDType.Texture2D:
                                SavePath = txt_Save.Text + "Texture\\";
                                if (File.Exists(SavePath + fileName + ".png"))
                                {
                                    return;
                                }

                                if (!Directory.Exists(SavePath))
                                {
                                    Directory.CreateDirectory(SavePath);
                                }
                                var m_Texture2D = new Texture2D(OR);
                                var converter   = new Texture2DConverter(m_Texture2D);
                                var bitmap      = converter.ConvertToBitmap(true);
                                if (bitmap != null)
                                {
                                    if (fileName.StartsWith("Card"))
                                    {
                                        if (!fileName.Contains("std") && !fileName.EndsWith("w_png") && (bitmap.Width == 1024 && bitmap.Height == 1024))
                                        {
                                            bitmap = bitmap.ResizeImage(1024, 1331);
                                        }
                                    }
                                    else if (fileName.StartsWith("Location"))
                                    {
                                        if (bitmap.Width == 512 && bitmap.Height == 512)
                                        {
                                            bitmap = bitmap.ResizeImage(768, 512);
                                        }
                                        else if (bitmap.Width == 1024 && bitmap.Height == 1024)
                                        {
                                            bitmap = bitmap.ResizeImage(1536, 1024);
                                        }
                                    }
                                    else if (fileName.Contains("loginBonus_bg") && (bitmap.Width == 1024 && bitmap.Height == 1024))
                                    {
                                        bitmap = bitmap.ResizeImage(1024, 1536);
                                    }

                                    bitmap.Save(SavePath + fileName + ".png", ImageFormat.Png);
                                    bitmap.Dispose();
                                }

                                m_Texture2D = null;
                                break;

                            case ClassIDType.AudioClip:
                                SavePath = txt_Save.Text + "Audio\\";

                                if (fileName.StartsWith("Sound_Voice"))
                                {
                                    string[] path    = fileName.Split(new char[] { '_' });
                                    string finalPath = "";
                                    for (int i = 0; i < path.Length - 2; i++)
                                    {
                                        finalPath += path[i] + "_";
                                    }
                                    SavePath += finalPath.Remove(finalPath.Length - 1) + "\\";
                                }

                                if (!Directory.Exists(SavePath))
                                {
                                    Directory.CreateDirectory(SavePath);
                                }

                                AudioClip m_AudioClip  = new AudioClip(OR);
                                var audioClipConverter = new AudioClipConverter(m_AudioClip);

                                if (audioClipConverter.IsFMODSupport)
                                {
                                    byte[] m_AudioData = audioClipConverter.ConvertToWav();
                                    File.WriteAllBytes(SavePath + fileName + ".wav", m_AudioData);
                                }
                                else
                                {
                                    byte[] m_AudioData = m_AudioClip.m_AudioData.Value;
                                    File.WriteAllBytes(SavePath + fileName + audioClipConverter.GetExtensionName(), m_AudioData);
                                }

                                m_AudioClip = null;
                                break;

                            case ClassIDType.TextAsset:
                                SavePath = txt_Save.Text + "Text\\";
                                if (!Directory.Exists(SavePath))
                                {
                                    Directory.CreateDirectory(SavePath);
                                }
                                TextAsset TA = new TextAsset(OR);
                                File.WriteAllBytes(SavePath + fileName + ".txt", TA.m_Script);
                                TA = null;
                                break;
                            }
                        }
                    }
                    else
                    {
                        string SavePath = txt_Save.Text + "Unity3D\\";
                        if (!Directory.Exists(SavePath))
                        {
                            Directory.CreateDirectory(SavePath);
                        }
                        SetToolStripLabelText("略過: " + fileName, lab_Execute);
                        File.Move(item.originalPath, SavePath + fileName + ".unity3d");
                    }

                    SetProgressBarValue(PB_TotalFile.Value + 1, PB_TotalFile);
                    tbManager.SetProgressValue(PB_TotalFile.Value, extFile.Count);
                    SetToolStripLabelText("已解包數: " + PB_TotalFile.Value, lab_DownItem);
                });

                assetsManager.Clear();
                extFile.Clear();
                GC.Collect();
            }

            SW.Stop();
            timer1.Stop();
            SetLabelText("下載檔案:無", lab_Download);
            SetToolStripLabelText("等待中", lab_Status);
            Work_Event(false);
            tbManager.SetProgressState(TaskbarProgressBarState.NoProgress);
            Invoke(new Action(delegate { Text = "清單檔案下載器 "; }));
            if (Program.autoClose)
            {
                Environment.Exit(1);
            }
            if (lib_Error.Items.Count <= 0)
            {
                SetButtonEnable(false, btn_Save_Error);
            }
            Environment.ExitCode = 1;
            MessageBox.Show("下載完成");
        }
Ejemplo n.º 2
0
        private void RunDownload()
        {
            string Extension = (chb_Unity3d.Checked ? ".unity3d" : "");

            string[] FileList = lib_File.Items.Cast <string>().ToArray();
            tbManager.SetProgressValue(0, FileList.Length);
            tbManager.SetProgressState(TaskbarProgressBarState.Normal);
            string Url;

            if (rdb_ST.Checked)
            {
                Url = "http://img.wcproject.so-net.tw/assets/469/";
            }
            else if (rdb_SJ.Checked)
            {
                Url = "http://i-wcat-colopl-jp.akamaized.net/assets/465/";
            }
            else if (rdb_SK.Checked)
            {
                Url = "http://i-wcat-colopl-kr.akamaized.net/assets/465/";
            }
            else if (rdb_tennis.Checked)
            {
                Url = "http://i-tennis-colopl-jp.akamaized.net/asset_bundle/";
            }
            else
            {
                Url = txt_URL.Text;
            }

            if (rdb_tennis.Checked && RB_A.Checked)
            {
                Url += "android/0.0.1/";
            }
            else if (rdb_tennis.Checked && RB_I.Checked)
            {
                Url += "ios/0.0.1/";
            }
            else if (!rdb_Custom.Checked && RB_A.Checked)
            {
                Url += "a/";
            }
            else if (!rdb_Custom.Checked && RB_I.Checked)
            {
                Url += "i/";
            }

            List <DownloadInfo> list = new List <DownloadInfo>();

            SetProgressBarValue(0, PB_TotalFile);
            foreach (string fileName in FileList)
            {
                if (fileName == "" || fileName.Substring(0, 1) == "'")
                {
                    DelListBox(fileName.ToString(), lib_File);
                }
                else
                {
                    string       urlAddress = Url + fileName + Extension + "?r=" + DateTime.Now.ToFileTime().ToString();
                    DownloadInfo info       = new DownloadInfo(urlAddress, txt_Save.Text, this, fileName + ".unity3d");
                    list.Add(info);
                    info.StartDownload();
                }
            }
            list.ForEach(delegate(DownloadInfo item)
            {
                SetToolStripLabelText("下載中 (" + (PB_TotalFile.Value * 100.0 / list.Count).ToString("0.0") + "%)", lab_Status);
                while (!item.IsDone)
                {
                    if (!Working)
                    {
                        if (item.WC != null)
                        {
                            item.WC.CancelAsync();
                        }
                        break;
                    }
                    SetLabelText("下載檔案: " + item.FileName, lab_Download);
                    SetLabelText(string.Format("{0} KB / {1} KB", item.KBytesReceived.ToString("0.0"), item.TotalKBytesToReceive.ToString("0.0")), lab_Speed);
                    SetProgressBarValue(item.KBytesReceived, PB_SingleFile);
                    SetProgressBarMaxValue(item.TotalKBytesToReceive, PB_SingleFile);
                    Thread.Sleep(500);
                }
                if (item.IsCancelled)
                {
                    AddListBoxItem("C." + item.FileName, lib_Error);
                }
                else if (item.Error != "")
                {
                    AddListBoxItem("E." + item.FileName, lib_Error);
                }
                SetProgressBarValue(PB_TotalFile.Value + 1, PB_TotalFile);
                SetToolStripLabelText("錯誤檔案數: " + lib_Error.Items.Count.ToString(), lab_ErrorItem);
                SetToolStripLabelText("已下載數: " + PB_TotalFile.Value, lab_DownItem);
                DelListBox(Path.GetFileNameWithoutExtension(item.FileName), lib_File);
                tbManager.SetProgressValue(PB_TotalFile.Value, FileList.Length);
            });
            list.Clear();
            SetProgressBarValue(0, PB_SingleFile);
            SetProgressBarMaxValue(0, PB_SingleFile);
            SetLabelText("0 KB / 0 KB", lab_Speed);
            if (ExtFile.Count != 0)
            {
                if (!Directory.Exists(txt_Save.Text))
                {
                    Directory.CreateDirectory(txt_Save.Text);
                }
                SetToolStripLabelText("檔案數: " + ExtFile.Count, lab_Item);
                SetProgressBarValue(0, PB_TotalFile);
                SetProgressBarMaxValue(ExtFile.Count, PB_TotalFile);
                SetToolStripLabelText("解包中", lab_Status);
                Parallel.ForEach(ExtFile, (item) =>
                {
                    if (item.Key == null || item.Value == null)
                    {
                        return;
                    }
                    BundleFile BF = new BundleFile(item.Value);
                    if (!TSM_OnlyBundle.Checked)
                    {
                        bool Export = true;
                        if (TSM_UnPrefab.Checked && TSM_Exclude.Text != "")
                        {
                            foreach (string item2 in TSM_Exclude.Text.Split(new char[] { ',' }))
                            {
                                if (Path.GetFileNameWithoutExtension(item.Key).ToLower().Contains(item2.ToLower()))
                                {
                                    Export = false; break;
                                }
                            }
                        }
                        if (Export)
                        {
                            SetToolStripLabelText("解包: " + item.Key, lab_Execute);
                            using (EndianStream ES = new EndianStream(BF.MemoryAssetsFileList[0].memStream, EndianType.BigEndian))
                            {
                                AssetsFile AF = new AssetsFile(item.Key, ES);
                                foreach (var item2 in AF.preloadTable.Values)
                                {
                                    string SavePath = "";
                                    switch (item2.Type2)
                                    {
                                    case 28:
                                        SavePath = txt_Save.Text + "Texture\\";
                                        if (!Directory.Exists(SavePath))
                                        {
                                            Directory.CreateDirectory(SavePath);
                                        }
                                        var m_Texture2D = new Texture2D(item2, true);
                                        var bitmap      = m_Texture2D.ConvertToBitmap(true);
                                        if (bitmap != null)
                                        {
                                            if (!item.Key.Contains("std") && (bitmap.Width == 1024 && bitmap.Height == 1024))
                                            {
                                                bitmap = Static_Function.ResizeImage(bitmap, 1024, 1331);
                                            }
                                            bitmap.Save(SavePath + item.Key + ".png", ImageFormat.Png);
                                            bitmap.Dispose();
                                        }
                                        m_Texture2D = null;
                                        break;

                                    case 83:
                                        SavePath = txt_Save.Text + "Audio\\";
                                        if (!Directory.Exists(SavePath))
                                        {
                                            Directory.CreateDirectory(SavePath);
                                        }
                                        AudioClip m_AudioClip = new AudioClip(item2, true);
                                        File.WriteAllBytes(SavePath + item.Key + ".mp3", m_AudioClip.m_AudioData);
                                        m_AudioClip = null;
                                        break;

                                    case 49:
                                        SavePath = txt_Save.Text + "Text\\";
                                        if (!Directory.Exists(SavePath))
                                        {
                                            Directory.CreateDirectory(SavePath);
                                        }
                                        TextAsset TA = new TextAsset(item2, true);
                                        File.WriteAllBytes(SavePath + item.Key + ".txt", TA.m_Script);
                                        TA = null;
                                        break;

                                    case 114:
                                        SavePath = txt_Save.Text + "Text\\";
                                        if (!Directory.Exists(SavePath))
                                        {
                                            Directory.CreateDirectory(SavePath);
                                        }
                                        MonoBehaviour MB = new MonoBehaviour(item2, true);
                                        File.WriteAllText(SavePath + item.Key + ".txt", MB.serializedText);
                                        MB = null;
                                        break;
                                    }
                                }
                                AF = null;
                            }
                        }
                        else
                        {
                            SetToolStripLabelText("略過: " + item.Key, lab_Execute); Static_Function.WriteBundleFile(BF, txt_Save.Text + "CAB-" + item.Key);
                        }
                    }
                    else
                    {
                        SetToolStripLabelText("輸出: " + item.Key, lab_Execute); Static_Function.WriteBundleFile(BF, txt_Save.Text + "CAB-" + item.Key);
                    }
                    BF = null;
                    item.Value.Dispose();
                    SetProgressBarValue(PB_TotalFile.Value + 1, PB_TotalFile);
                    tbManager.SetProgressValue(PB_TotalFile.Value, ExtFile.Count);
                    SetToolStripLabelText("已解包數: " + PB_TotalFile.Value, lab_DownItem);
                });
                ExtFile.Clear();
                GC.Collect();
            }
            SW.Stop();
            timer1.Stop();
            SetLabelText("下載檔案:無", lab_Download);
            SetToolStripLabelText("等待中", lab_Status);
            Work_Event(false);
            tbManager.SetProgressState(TaskbarProgressBarState.NoProgress);
            Invoke(new Action(delegate { Text = "清單檔案下載器 "; }));
            if (Program.autoClose)
            {
                Environment.Exit(1);
            }
            if (lib_Error.Items.Count <= 0)
            {
                SetButtonEnable(false, btn_Save_Error);
            }
            Environment.ExitCode = 1;
            MessageBox.Show("下載完成");
        }