/// <summary> /// 一行一行解析 /// </summary> public void Load() { using (var stream = Fileinfo.OpenRead()) { StreamReader reader = new StreamReader(stream); var line = reader.ReadLine(); IniSection section = null; while (line != null) { //解析这一行 line = line.Trim(); if (line.StartsWith("#") || line.StartsWith("//") || line.Equals("")) { //注释,直接跳过 } if (line.StartsWith("[") && line.EndsWith("]")) { //section标识 if (section != null) { //将上一次解析的section存入列表 Sections.Add(section); //创建新的Section section = new IniSection(line, true); } else { section = new IniSection(line, true); } } if (line.Contains("=")) { var vs = line.Split('='); //创建键值对 KeyValuePair <string, string> pair = new KeyValuePair <string, string>(vs[0], vs[1]); if (section != null) { section.Values.Add(pair); } else { throw new Exception("Section不存在但解析到Key-Value对"); } } line = reader.ReadLine(); } if (section != null) { Sections.Add(section); } reader.Dispose(); reader.Close(); } }
public ActionResult DeleteFile(int id) { Fileinfo fi = db.Fileinfos.Find(id); db.Entry(fi).State = EntityState.Deleted; db.SaveChanges(); return(RedirectToAction("Index", "Home")); }
//private void PopulateTreeView(TreeNode parentNode, DirectoryInfo parentFolder) //{ // foreach (var item in parentFolder.GetDirectories()) // { // if (!item.Attributes.ToString().Contains("Hidden")) // { // TreeNode myNode = new TreeNode(item.Name); // myNode.Value = parentNode.Value + "/" + item.Name; // myNode.ToolTip = myNode.Value; // parentNode.ChildNodes.Add(myNode); // PopulateTreeView(myNode, item); // } // } //} private void BindData(string path) { path = Server.MapPath(path); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } DirectoryInfo dir = new DirectoryInfo(path); List <Fileinfo> list = new List <Fileinfo>(); foreach (var item in dir.GetDirectories()) { if (!item.Attributes.ToString().Contains("Hidden")) { Fileinfo model = new Fileinfo(); model.filetype = "folder"; model.filename = item.Name; model.filesize = 0; model.updatetime = item.LastWriteTime.ToString(); model.url = hidfilepath.Value + "/" + item.Name; list.Add(model); } } foreach (var item in dir.GetFiles()) { if (!item.Attributes.ToString().Contains("Hidden")) { Fileinfo model = new Fileinfo(); model.filetype = item.Extension.Replace(".", ""); model.filename = item.Name; model.filesize = (item.Length / 1024); model.updatetime = item.LastWriteTime.ToString(); model.url = hidfilepath.Value + "/" + item.Name; if (filetype.Contains(model.filetype.ToLower())) { list.Add(model); } } } DataTable dt = List2DataTable(list); dt.DefaultView.Sort = orderstr; gvList.DataSource = dt.DefaultView; gvList.DataBind(); spalert.InnerText = ""; }
public List<Fileinfo> ListFiles() { List<Fileinfo> list = new List<Fileinfo>(); string path = getPath(); foreach (string strFile in Directory.GetFiles(path, "*", SearchOption.TopDirectoryOnly)) { if (!strFile.Replace(path,"").Replace("\\","").StartsWith("v_")) { Fileinfo fi = new Fileinfo(strFile); fi.Uri = getUri(fi.Name); list.Add(fi); } } return list.OrderBy(x=>x.Name).ToList<Fileinfo>(); }
public List <Fileinfo> ListFiles() { List <Fileinfo> list = new List <Fileinfo>(); string path = getPath(); foreach (string strFile in Directory.GetFiles(path, "*", SearchOption.TopDirectoryOnly)) { if (!strFile.Replace(path, "").Replace("\\", "").StartsWith("v_")) { Fileinfo fi = new Fileinfo(strFile); fi.Uri = getUri(fi.Name); list.Add(fi); } } return(list.OrderBy(x => x.Name).ToList <Fileinfo>()); }
/// <summary> /// 获取保存文件信息 /// </summary> /// <param name="FileName"></param> /// <param name="WhatDoIWant"></param> /// <returns></returns> private string GetFileInfo(string FileName, Fileinfo WhatDoIWant) { int iLastIndex = 0; string cWantedSubstring = ""; iLastIndex = FileName.LastIndexOf("\\"); if (WhatDoIWant == Fileinfo.Name) { cWantedSubstring = FileName.Substring(iLastIndex + 1); } else if (WhatDoIWant == Fileinfo.Path) { cWantedSubstring = FileName.Remove(iLastIndex, FileName.Substring(iLastIndex).Length); } return(cWantedSubstring); }
public ActionResult Create(Fileinfo model, HttpPostedFileBase someFile) { Fileinfo fi = new Fileinfo(); fi.FileName = Path.GetFileName(someFile.FileName); fi.ContentType = someFile.ContentType; using (var reader = new BinaryReader(someFile.InputStream)) { fi.Content = reader.ReadBytes(someFile.ContentLength); } db.Fileinfos.Add(fi); db.SaveChanges(); return(RedirectToAction("Index", "Home")); }
private void btnBrowse_Click(object sender, EventArgs e) { try { strlistfile = new List <String>(); listfile = new List <Fileinfo>(); OpenFileDialog ofdFile = new OpenFileDialog(); ofdFile.Multiselect = true; ofdFile.Filter = "All files (*.*)|*.*"; ofdFile.Title = "Select File."; if (ofdFile.ShowDialog() == DialogResult.OK) { var files = ofdFile.FileNames; int totalfile = files.Length; int i = 0; btnUpload.Text = "Processing: (" + totalfile + ") " + ((totalfile <= 1) ? "File" : "Files").ToString(); if (totalfile > 0) { foreach (var file in files) { i++; txtFile.Text = file; Fileinfo objfile = new Fileinfo() { Id = i, Filename = Path.GetFileName(file), Filesource = file, Filedestination = strHostdest + Path.GetFileName(file), }; listfile.Add(objfile); GenerateLine(file, i); } } richTextBox1.Lines = strlistfile.ToArray(); richTextBox1.SelectAll(); richTextBox1.SelectionColor = Color.Black; } btnUpload.Text = "Upload"; } catch (Exception ex) { ex.ToString(); } }
public ActionResult DownloadFile(int id) { Fileinfo fi = db.Fileinfos.Find(id); return(File(fi.Content, fi.ContentType, fi.FileName)); }
private void ReadDataFile(string fileName, Fileinfo fileType) { var txtFile = (TextAsset)Resources.Load(fileName); var lineList = txtFile.text.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None); var lineListLen = lineList.Length; var formerSceneName = ""; var formerIndex = 0; for (var i = 0; i < lineListLen; i++) { var wordList = lineList[i].Split('\t'); int index; switch (fileType) { case Fileinfo.Combinetable: var material1 = Convert.ToInt32(wordList[0]); var material2 = Convert.ToInt32(wordList[1]); var resultNum = Convert.ToInt32(wordList[2]); Tuple <int, int> tuple; if (material1 != material2) { tuple = new Tuple <int, int>(material2, material1); CombineDic[tuple] = new List <int>(); for (var j = 0; j < resultNum; j++) { CombineDic[tuple].Add(Convert.ToInt32(wordList[3 + j])); } } tuple = new Tuple <int, int>(material1, material2); CombineDic[tuple] = new List <int>(); for (var j = 0; j < resultNum; j++) { CombineDic[tuple].Add(Convert.ToInt32(wordList[3 + j])); } break; case Fileinfo.Itemtable: index = Convert.ToInt32(wordList[0]); var group = wordList[2]; var sellPrice = Convert.ToInt32(wordList[4]); switch (group) { case "별": // 별 StarNum++; break; case "재료": // 재료 MaterialNum++; break; case "아이템": // 아이템 CombineNum++; break; case "기타": // 기타 EtcNum++; break; } // 인덱스, 이름, 분류, 등급, 판매 가격, 설명, 이미지 경로 FindItemDic[index] = new ItemInfo(index, wordList[1], group, wordList[3], sellPrice, wordList[5], "itemImg/item_" + index); break; case Fileinfo.Setitemtable: var setItemInfo = new SetItemInfo(Convert.ToInt32(wordList[0]), Convert.ToInt32(wordList[1]), Convert.ToInt32(wordList[2]), Convert.ToInt32(wordList[3]), Convert.ToInt32(wordList[4])); SetCombineList.Add(setItemInfo); break; case Fileinfo.Questtable: index = Convert.ToInt32(wordList[0]); var dialogueStart = Convert.ToInt32(wordList[2]); var dialogueEnd = Convert.ToInt32(wordList[3]); var termsNum = Convert.ToInt32(wordList[6]); var rewardNum = Convert.ToInt32(wordList[19]); FindQuestDic[index] = new QuestInfo(index, wordList[1], dialogueStart, dialogueEnd, wordList[4], wordList[5]); for (var arrIdx = 0; arrIdx < termsNum; arrIdx++) { FindQuestDic[index].SetTermsDic(Convert.ToInt32(wordList[7 + 2 * arrIdx]), Convert.ToInt32(wordList[8 + 2 * arrIdx])); } for (var arrIdx = 0; arrIdx < rewardNum; arrIdx++) { FindQuestDic[index].SetRewardDic(Convert.ToInt32(wordList[20 + 2 * arrIdx]), Convert.ToInt32(wordList[21 + 2 * arrIdx])); } /*Debug.Log(wordList[4]);*/ if (wordList[1] != formerSceneName) // 씬의 첫 퀘스트의 인덱스 구하기 { FirstQuestsOfScene.Add(index); if (formerSceneName != "") { LastQuestsOfScene.Add(formerIndex); } formerSceneName = wordList[1]; } if (i == lineListLen - 1) //마지막 인덱스 집어넣기 { LastQuestsOfScene.Add(index); } formerIndex = index; break; case Fileinfo.Upgradetable: index = Convert.ToInt32(wordList[0]); var len = (wordList.Length - 2) / 2; // wordList의 앞 두 개는 각각 이름과 설명이므로 -2, 그리고 (효과,값)쌍이므로 /2 UpgradeInfo upInfo; upInfo.Index = index; upInfo.Name = wordList[1]; upInfo.Value = new int[len]; upInfo.Cost = new int[len]; for (var j = 0; j < len; j++) { var value = Convert.ToInt32(wordList[2 * j + 2]); var cost = Convert.ToInt32(wordList[2 * j + 3]); upInfo.Value[j] = value; upInfo.Cost[j] = cost; } FindUpDic[index] = upInfo; break; case Fileinfo.Dialoguetable: index = Convert.ToInt32(wordList[0]); // wordList[1] : name, wordList[2] : dialogue, wordList[3] : face, wordList[4] : sound //Debug.Log(String.Format("{0} {1}: {2} {3} + {4}",index, wordList[1], wordList[2], wordList[3], wordList[4])); 메테스가 민 대사 말하는 현상 수정용 DialogueDic[index] = new TextInfo(wordList[1], wordList[2], wordList[3], wordList[4]); break; default: throw new ArgumentOutOfRangeException("fileType", fileType, null); } } }
void FtpUploadFile(Fileinfo file) { FtpWebRequest ftpRequest = null; FileStream filestream = null; Stream stream = null; try { currentPosition = 0; totalTransfered = 0; size = 0; transferRate = 0; FileInfo fileInfo = new FileInfo(file.Filesource); size = fileInfo.Length; progbarFtp.Minimum = 0; progbarFtp.Maximum = 100; long currentSize = 0; long incrementSize = (size / 100); string _strHostName = strHostName + "/" + file.Filedestination; filestream = new FileStream(file.Filesource, FileMode.Open, FileAccess.Read); ftpRequest = FtpWebRequest.Create(_strHostName) as FtpWebRequest; ftpRequest.Method = WebRequestMethods.Ftp.UploadFile; ftpRequest.Credentials = new NetworkCredential(strUserName, strPassword); ftpRequest.UseBinary = true; ftpRequest.KeepAlive = false; ftpRequest.UsePassive = true; ftpRequest.Timeout = Int32.MaxValue; ftpRequest.ReadWriteTimeout = Int32.MaxValue; stream = ftpRequest.GetRequestStream(); const int bufferLength = (1 * 1024); byte[] buffer = new byte[bufferLength]; int read = 0; while ((read = filestream.Read(buffer, 0, buffer.Length)) != 0) { stream.Write(buffer, 0, read); currentSize += read; totalTransfered += read; transferRate = read; if (currentSize >= incrementSize) { currentSize -= incrementSize; progbarFtp.Invoke(new updatebar(this.UpdateProgress)); } } stream.Flush(); } catch (Exception ex) { MessageBox.Show("Connection Error!!", "Message"); ex.ToString(); } finally { if (filestream != null) { filestream.Close(); filestream.Dispose(); } if (stream != null) { stream.Close(); stream.Dispose(); } if (ftpRequest != null) { ftpRequest = null; } if (ftpResponse != null) { ftpResponse.Close(); } } }
List <Fileinfo> getDirectoryFiles() { FtpWebRequest ftpRequest = null; List <Fileinfo> resultlistFile = null; try { strHostName = txtHost.Text.Trim(); strUserName = txtusername.Text.Trim(); strPassword = txtPassword.Text.Trim(); strPort = txtPort.Text.Trim(); if ((strHostName != string.Empty) && (strUserName != string.Empty) && (strPassword != string.Empty)) { //FTP Request string _strHostName = strHostName + "/" + strHostdest; ftpRequest = (FtpWebRequest)FtpWebRequest.Create(_strHostName); ftpRequest.Credentials = new NetworkCredential(strUserName, strPassword); ftpRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails; ftpRequest.UseBinary = true; ftpRequest.KeepAlive = false; ftpRequest.UsePassive = true; ftpRequest.Timeout = Int32.MaxValue; ftpRequest.ReadWriteTimeout = Int32.MaxValue; ftpResponse = (FtpWebResponse)ftpRequest.GetResponse(); //Read Directory string[] listFile = null; using (StreamReader reader = new StreamReader(ftpResponse.GetResponseStream())) { string strFiles = reader.ReadToEnd(); listFile = strFiles.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); } if (listFile.Length > 0) { resultlistFile = new List <Fileinfo>(); int i = 0; foreach (string file in listFile) { i++; //GET FileInformation string filename = file; filename = filename.Remove(0, 24); filename = filename.Trim(); string[] fileinfo = filename.Split(' '); if (fileinfo.Length > 2) { string _filename = string.Empty; for (int j = 1; j < fileinfo.Length; j++) { _filename += fileinfo[j] + ' '; } filename = _filename; } else { filename = fileinfo[1]; } string filesize = ToFileSize(Convert.ToDouble(fileinfo[0])); string date = file.Substring(0, 17); //SET FileInformation Fileinfo item = new Fileinfo() { Id = i, DateCreated = DateTime.Parse(date), Filename = filename, Filesize = filesize }; resultlistFile.Add(item); } } } } catch (Exception ex) { MessageBox.Show("Connection Error!!", "Message"); ex.ToString(); } finally { if (ftpRequest != null) { ftpRequest = null; } if (ftpResponse != null) { ftpResponse.Close(); } } return(resultlistFile); }
//private void PopulateTreeView(TreeNode parentNode, DirectoryInfo parentFolder) //{ // foreach (var item in parentFolder.GetDirectories()) // { // if (!item.Attributes.ToString().Contains("Hidden")) // { // TreeNode myNode = new TreeNode(item.Name); // myNode.Value = parentNode.Value + "/" + item.Name; // myNode.ToolTip = myNode.Value; // parentNode.ChildNodes.Add(myNode); // PopulateTreeView(myNode, item); // } // } //} private void BindData(string path) { path = Server.MapPath(path); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } DirectoryInfo dir = new DirectoryInfo(path); List<Fileinfo> list = new List<Fileinfo>(); foreach (var item in dir.GetDirectories()) { if (!item.Attributes.ToString().Contains("Hidden")) { Fileinfo model = new Fileinfo(); model.filetype = "folder"; model.filename = item.Name; model.filesize = 0; model.updatetime = item.LastWriteTime.ToString(); model.url = hidfilepath.Value + "/" + item.Name; list.Add(model); } } foreach (var item in dir.GetFiles()) { if (!item.Attributes.ToString().Contains("Hidden")) { Fileinfo model = new Fileinfo(); model.filetype = item.Extension.Replace(".", ""); model.filename = item.Name; model.filesize = (item.Length / 1024); model.updatetime = item.LastWriteTime.ToString(); model.url = hidfilepath.Value + "/" + item.Name; if (filetype.Contains(model.filetype.ToLower())) { list.Add(model); } } } DataTable dt = List2DataTable(list); dt.DefaultView.Sort = orderstr; gvList.DataSource = dt.DefaultView; gvList.DataBind(); spalert.InnerText = ""; }