예제 #1
0
        public bool SaveProject(Form baseFrom = null, bool SaveAs = false)
        {
            FormSpaner.LockFrom(baseFrom);
            FormSpaner.SetFromProcess(0, "设置Chorista文件", baseFrom);
            ProjectObject currentClone = (ProjectObject)projectObject.Clone();
            string        TargetFile   = projectObject.BasicData.ProjectFilePath;

            if (SaveAs)
            {
                TargetFile = "";
            }
            if (TargetFile == "")
            {
                SaveFileDialog sfd = new SaveFileDialog();
                if (!SaveAs)
                {
                    sfd.Title = "保存";
                }
                sfd.Filter          = "Chorista工程(*.hymn)|*.hymn|全部文件(*.*)|*.*";
                sfd.FilterIndex     = 0;
                sfd.OverwritePrompt = true;
                if (sfd.ShowDialog(baseFrom) == DialogResult.OK)
                {
                    TargetFile = sfd.FileName;
                }
            }
            if (TargetFile == "")
            {
                FormSpaner.UnLockFrom(baseFrom);
                return(false);
            }
            try
            {
                FormSpaner.SetFromProcess(50, "保存工程", baseFrom);
                ProjectObject.Serializer.SerializeToFile(currentClone, TargetFile, ObjectSerializer <ProjectObject> .SerializeType.JSON, true);
                if (!System.IO.File.Exists(projectObject.BasicData.ProjectFilePath))
                {
                    projectObject.BasicData.ProjectFilePath = TargetFile;
                }
                FormSpaner.SetFromProcess(100, "完成", baseFrom);
                FormSpaner.UnLockFrom(baseFrom);
                tw.Text = projectObject.BasicData.ProjectFilePath;
                if (System.IO.File.Exists(tw.Text))
                {
                    tw.Text = "Project : " + (new System.IO.FileInfo(tw.Text)).Name;
                }
                return(true);
            }
            catch {; }
            FormSpaner.UnLockFrom(baseFrom);
            return(false);
        }
예제 #2
0
        public bool OpenUSTs(Form baseFrom = null)
        {
            FormSpaner.LockFrom(baseFrom);
            FormSpaner.SetFromProcess(0, "查找UST文件", baseFrom);
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter          = "utau工程(*.ust)|*.ust|全部文件(*.*)|*.*";
            ofd.FilterIndex     = 0;
            ofd.CheckFileExists = true;
            ofd.Multiselect     = true;
            if (ofd.ShowDialog(baseFrom) == DialogResult.OK)
            {
                try
                {
                    FormSpaner.SetFromProcess(5, "有效性验证", baseFrom);
                    string[]      FileList = ofd.FileNames;
                    List <string> RealList = new List <string>();
                    for (int i = 0; i < FileList.Length; i++)
                    {
                        if (System.IO.File.Exists(FileList[i]))
                        {
                            RealList.Add(FileList[i]);
                        }
                    }
                    ProjectObject Proj = new ProjectObject();
                    Proj.InitEmpty();
                    Proj.BasicData.IntroduceText   = "";
                    Proj.BasicData.ProjectFilePath = "";
                    Proj.BasicData.SavePassword    = "";
                    Proj.SingerList.Clear();
                    Proj.TrackerList.Clear();
                    Proj.BackerList.Clear();

                    FormSpaner.SetFromProcess(10, "正在装载UST文件", baseFrom);
                    Object thisLock = new Object();
                    Parallel.For(0, RealList.Count, (i) =>
                    {
                        USTOriginalProject USTPO = USTOriginalSerializer.Deserialize(RealList[i]);
                        PartsObject pro          = USTOriginalSerializer.UST2Parts(USTPO);
                        TrackerObject toj        = new TrackerObject((uint)i);
                        toj.Name = pro.PartName;
                        toj.PartList.Clear();
                        toj.PartList.Add(pro);
                        lock (thisLock)
                        {
                            Proj.TrackerList.Add(toj);
                        }
                    });
                    Proj.TrackerList.Sort();
                    FormSpaner.SetFromProcess(90, "正在装载工程文件", baseFrom);
                    LoadProjectObject(ref Proj);
                    FormSpaner.SetFromProcess(100, "完成", baseFrom);
                    FormSpaner.UnLockFrom(baseFrom);
                    tw.Text = "UnsavedProject";
                    return(true);
                }
                catch {; }
            }
            FormSpaner.UnLockFrom(baseFrom);
            return(false);
        }
예제 #3
0
        public bool OpenProject(Form baseFrom = null)
        {
            FormSpaner.LockFrom(baseFrom);
            FormSpaner.SetFromProcess(0, "查找Chorista文件", baseFrom);
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter          = "Chorista工程(*.hymn)|*.hymn|全部文件(*.*)|*.*";
            ofd.FilterIndex     = 0;
            ofd.CheckFileExists = true;
            if (ofd.ShowDialog(baseFrom) == DialogResult.OK)
            {
                try
                {
                    FormSpaner.SetFromProcess(10, "工程信息读取", baseFrom);
                    ObjectDeserializer <ProjectObject> DPO = new ObjectDeserializer <ProjectObject>();
                    BasicFileInformation bfi = DPO.ReadBasicInformation(ofd.FileName);
                    if (bfi.VersionString != BasicFileInformation.currentVersion)
                    {
                        MessageBox.Show("文件版本错误!请使用最新版本的文件转换助理进行版本转换!");
                        FormSpaner.UnLockFrom(baseFrom);
                        return(false);
                    }
                    bool          Logined = false;
                    ProjectObject OOP     = null;
                    FormSpaner.SetFromProcess(30, "工程权限认证", baseFrom);
                    while (!Logined)
                    {
                        bool havePwd = false;
                        try
                        {
                            havePwd = (bfi.SavePassword.Length > 0 || bfi.IntroduceText.Trim().Length > 0);
                            if (havePwd)
                            {
                                IntroduceSwap ISW = new IntroduceSwap(bfi);
                                if (ISW.ShowDialog() != DialogResult.OK)
                                {
                                    MessageBox.Show("用户已取消");
                                    Logined = true;
                                    FormSpaner.UnLockFrom(baseFrom);
                                    return(false);
                                }
                            }
                            OOP = DPO.DeserializeFromFile(ofd.FileName, bfi, ObjectSerializer <ProjectObject> .SerializeType.JSON, true);
                            OOP.BasicData.ProjectFilePath = ofd.FileName;
                            Logined = true;
                        }
                        catch
                        {
                            if (havePwd)
                            {
                                MessageBox.Show("文件打开失败!可能密码输入错误或文件已损坏!");
                                Logined = false;
                            }
                            else
                            {
                                MessageBox.Show("文件打开失败!");
                                FormSpaner.UnLockFrom(baseFrom);
                                return(false);
                            }
                        }
                    }
                    if (OOP != null)
                    {
                        FormSpaner.SetFromProcess(80, "装载工程", baseFrom);
                        LoadProjectObject(ref OOP);
                        tw.Text = OOP.BasicData.ProjectFilePath;
                        if (System.IO.File.Exists(tw.Text))
                        {
                            tw.Text = "Project : " + (new System.IO.FileInfo(tw.Text)).Name;
                        }
                    }
                    else
                    {
                        MessageBox.Show("工程解析异常!");
                        FormSpaner.UnLockFrom(baseFrom);
                        return(false);
                    }
                }
                catch
                {
                    MessageBox.Show("未知错误");
                    FormSpaner.UnLockFrom(baseFrom); return(false);
                }
                FormSpaner.SetFromProcess(100, "完成", baseFrom);
                FormSpaner.UnLockFrom(baseFrom);
                return(true);
            }
            else
            {
                FormSpaner.UnLockFrom(baseFrom);
                return(false);
            }
        }