예제 #1
0
        /// <summary>
        /// 将srcFile拷贝到System资源文件夹里,返回资源文件ID
        /// </summary>
        static string ImportResourceFile(string srcFile)
        {
            SdsiteXmlDocument      doc     = Service.Sdsite.CurrentDocument;
            FileSimpleExXmlElement fileEle = doc.CreateFileElement(doc.Resources.SystemFolder, srcFile);

            return(fileEle.Id);
        }
예제 #2
0
        /// <summary>
        ///  保存/替换文件
        /// </summary>
        /// <param name="isReplace">true 替换文件 , false 只保存</param>
        /// <returns>保存/替换成功 返回TRUE 失败 FALSE</returns>
        private bool SaveOrReplaceFile(bool isReplace, string fileName)
        {
            SdsiteXmlDocument doc = Service.Sdsite.CurrentDocument;

            if (isReplace)
            {
                DialogResult result = MessageService.Show("${res:Tree.msg.coverFile}", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                if (result == DialogResult.Cancel)
                {
                    return(false);
                }

                //旧文件删除
                foreach (MyListItem item in listViewFodel.Items)
                {
                    if (item is MyListFileItem)
                    {
                        MyListFileItem fileItem = item as MyListFileItem;
                        if (fileName.Equals(fileItem.Element.FileName, StringComparison.CurrentCultureIgnoreCase))
                        {
                            MyListItem deleItem = fileItem as MyListItem;
                            doc.DeleteItem(deleItem.Element);
                            listViewFodel.Items.Remove(deleItem);
                        }
                    }
                }
            }
            //保存新文件
            if (myResourceCurrentItem != null)
            {
                string strSrcFile = Path.Combine(myResourceCurrentItem.Element.AbsoluteFilePath, fileName);
                _image.Save(strSrcFile, _imgFormat);
                FileSimpleExXmlElement fileEle = doc.CreateFileElement(myResourceCurrentItem.Element as FolderXmlElement, strSrcFile);
                InitListView(myResourceCurrentItem, listViewFodel, _resourceCurrentType);

                this.DialogResult = DialogResult.OK;
            }



            return(true);
        }
예제 #3
0
        /// <summary>
        /// 导入资源文件
        /// </summary>
        public void ImportResource()
        {
            SdsiteXmlDocument  doc      = Service.Sdsite.CurrentDocument;
            FormOpenFileDialog OpenFile = new FormOpenFileDialog();

            OpenFile.OpenDialog.Multiselect = true;
            OpenFile.OpenDialog.Filter      = "PIC files (*.jpg,*.png,*.gif)|*.jpg;*.png;*.gif;|Flash files (.swf)|*.swf|Media files (*.rmvb,*.rm,*.avi,*.wmv)|*.rmvb;*.rm;*.avi;*.wmv|Audio files (*.mp3,*.mdi,*.wma,*.wav)|*.mp3;*.mid;*.wma;*.wav";

            BaseFolderElementNode pathNode = CurrentNode as BaseFolderElementNode;
            string parentFolderID          = ((ElementNode)CurrentNode).Element.Id;

            if (OpenFile.ShowDialog(this) == DialogResult.OK)
            {
                string[] fileNames = OpenFile.OpenDialog.FileNames;
                foreach (string srcFilePath in fileNames)
                {
                    FileSimpleExXmlElement fileEle = doc.CreateFileElement(parentFolderID, srcFilePath);
                }
            }
        }
예제 #4
0
        private void imageToolStripMenuItem_Click(object sender, EventArgs e)
        {//导入资源
            SdsiteXmlDocument doc            = Service.Sdsite.CurrentDocument;
            MyListItem        importFolder   = null;
            string            openfileFilter = "";

            ToolStripMenuItem menuItem = (ToolStripMenuItem)(sender);

            switch (menuItem.Name)
            {
            case "imageToolStripMenuItem":
                openfileFilter = "PIC files (*.jpg,*.gif)|*.jpg;*.gif;";
                break;

            case "medioFileToolStripMenuItem":
                openfileFilter  = "Audio files (*.mp3,*.mdi,*.wma,*.wav)|*.mp3;*.mid;*.wma;*.wav;|";
                openfileFilter += "Media files (*.rmvb,*.rm,*.avi,*.wmv)|*.rmvb;*.rm;*.avi;*.wmv;|";
                openfileFilter += "Flash files (.swf)|*.swf;";
                break;

            case "documentFileToolStripMenuItem":
                openfileFilter = "doc files (*.txt,*.doc)|*.txt;*.doc;";
                break;

            case "compressFileNewToolStripMenuItem":
                openfileFilter = "Compress files (*.rar,*.zip)|*.rar;*.zip;";
                break;
            }

            FormOpenFileDialog OpenFile = new FormOpenFileDialog();

            OpenFile.OpenDialog.Multiselect = true;
            OpenFile.OpenDialog.Filter      = openfileFilter;
            if (OpenFile.ShowDialog(this) == DialogResult.OK)
            {
                string[] fileNames = OpenFile.OpenDialog.FileNames;
                foreach (string srcFilePath in fileNames)
                {
                    if (resourceFilesListView.SelectedItems.Count > 0 && resourceFilesListView.SelectedItems[0] is MyListFolderItem)
                    {
                        importFolder = (resourceFilesListView.SelectedItems[0] as MyListItem);
                        MyListItem item = ItemContains(resourceFilePaths, importFolder);
                        if (item != null)
                        {
                            importFolder = item;
                        }
                        parentResToolStripButton.Enabled = true;
                        myResourceCurrentItem            = importFolder;
                    }
                    else
                    {
                        importFolder = myResourceCurrentItem;
                    }
                    FileSimpleExXmlElement fileEle = doc.CreateFileElement(importFolder._element as FolderXmlElement, srcFilePath);
                }
                if (importFolder != null)
                {
                    InitListView(importFolder, resourceFilesListView, _resourceCurrentType);
                }
            }
        }
예제 #5
0
        /// <summary>
        /// 导入资源文件方法
        /// </summary>
        void ImportResources()
        {
            try
            {
                string newFilePath = string.Empty;
                SimpleExIndexXmlElement importFolder = null;
                SdsiteXmlDocument       doc          = Service.Sdsite.CurrentDocument;
                FormOpenFileDialog      OpenFile     = new FormOpenFileDialog();
                #region 筛选处理
                OpenFile.OpenDialog.Multiselect = true;
                string openfileFilter = "";
                switch (fileType)
                {
                case MediaFileType.Pic: openfileFilter = "PIC files (*.jpg,*.gif)|*.jpg;*.gif;"; break;

                case MediaFileType.Flash: openfileFilter = "Flash files (.swf)|*.swf"; break;

                case MediaFileType.Video: openfileFilter = "Media files (*.rmvb,*.rm,*.avi,*.wmv)|*.rmvb;*.rm;*.avi;*.wmv"; break;

                case MediaFileType.Audio: openfileFilter = "Audio files (*.mp3,*.mdi,*.wma,*.wav)|*.mp3;*.mid;*.wma;*.wav"; break;
                }
                OpenFile.OpenDialog.Filter = openfileFilter;
                #endregion
                if (OpenFile.ShowDialog(this) == DialogResult.OK)
                {
                    string[] fileNames = OpenFile.OpenDialog.FileNames;
                    foreach (string srcFilePath in fileNames)
                    {
                        if (listView.SelectedItems.Count > 0 && listView.SelectedItems[0] is MyFolderItem)
                        {
                            importFolder = (listView.SelectedItems[0] as MyItem)._element;// filePaths[pathNum].AbsoluteFilePath;
                            filePaths.Add(importFolder);
                            pathNum++;
                            backToolStripButton.Enabled = upToolStripButton.Enabled = true;
                        }
                        else
                        {
                            importFolder = filePaths[pathNum];
                            if (importFolder is FileSimpleExXmlElement)
                            {
                                importFolder = filePaths[pathNum - 1];
                            }
                        }

                        FileSimpleExXmlElement fileEle = doc.CreateFileElement(importFolder as FolderXmlElement, srcFilePath);
                        //#region 复制文件
                        /////将文件名翻译成拼音,生成一个不重名的文件名
                        //string fileName = Path.GetFileName(srcFilePath);
                        //string pinyinFileName = Utility.File.FormatFileName(fileName);
                        //string formatFileName = Utility.File.BuildFileName(importFolder.AbsoluteFilePath, pinyinFileName, false, true);

                        //bool isNoIn = false;//标识是否已经加载的资源文件
                        //if (listView.SelectedItems.Count > 0 && listView.SelectedItems[0] is MyFolderItem)
                        //{
                        //    importFolder = (listView.SelectedItems[0] as MyItem)._element;// filePaths[pathNum].AbsoluteFilePath;
                        //    filePaths.Add(importFolder);
                        //    pathNum++;
                        //    backToolStripButton.Enabled = upToolStripButton.Enabled = true;
                        //}
                        //else
                        //{
                        //    importFolder = filePaths[pathNum];
                        //    if (importFolder is FileSimpleExXmlElement)
                        //        importFolder = filePaths[pathNum - 1];
                        //}

                        //newFilePath = Path.Combine(importFolder.AbsoluteFilePath, formatFileName);

                        //if (File.Exists(newFilePath))
                        //{
                        //    if (MessageBox.Show("您确定要覆盖吗?", "确定", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        //    {
                        //        isNoIn = false;
                        //        File.Copy(srcFilePath, newFilePath, true);
                        //    }
                        //}
                        //else
                        //{
                        //    isNoIn = true;
                        //    File.Copy(srcFilePath, newFilePath);
                        //}

                        //#endregion
                        //#region 加入索引
                        //if (isNoIn)
                        //{
                        //    FileSimpleExXmlElement fileEle = doc.CreateFileElementNoCreateFile(importFolder as FolderXmlElement, formatFileName,fileName);
                        //}
                        //#endregion
                    }
                    if (importFolder != null)
                    {
                        InitListView(importFolder);
                    }
                }
            }
            catch { }
        }