private void FormScan_StartScan() { foreach (object obj in m_iconsinfo) { Info info = (Info)obj; string strfilename = string.Format(@"{0}\{1}", m_IconDir, info.fielname); if (File.Exists(strfilename)) { sprViewer.SPRItem si = new sprViewer.SPRItem(strfilename, info.frame); Image iconImage = si.IconImage; if (iconImage == null) { string filePath = si.TGAList["1"].ToString(); if (File.Exists(filePath)) { try { iconImage = Image.FromFile(filePath); } catch (Exception ex) { iconImage = null; } } } if (iconImage != null) { m_imglist.Images.Add(info.id.ToString(), iconImage); info.ImageIndex = m_imglist.Images.Count - 1; } else { info.ImageIndex = -1; } probar1.Value += 1; if (probar1.Value % 10 == 0) // Application.DoEvents效率很低,不必每次更新都要调1次 { label1.Text = info.fielname; Application.DoEvents(); } } else { info.ImageIndex = -1; } } this.Close(); }
public void ThreadProc() { if (m_threadExit) { return; } TreeView.CheckForIllegalCrossThreadCalls = false; DirectoryInfo di = new DirectoryInfo(((tree_tag)this.tv1.SelectedNode.Tag).strPath); ListView.ListViewItemCollection lvc = new ListView.ListViewItemCollection(this.lv1); foreach (FileInfo f in di.GetFiles()) { if (m_threadExit) { return; } Application.DoEvents(); fl.pbar.Value++; fl.label1.Text = f.FullName; if (strFilter.IndexOf(";" + f.Extension.ToLower() + ";") == -1) { continue; } if (imageList1.Images.ContainsKey(f.FullName)) { continue; } sprViewer.SPRItem.PIC_TYPE pt = sprViewer.SPRItem.PIC_TYPE.NULL; switch (f.Extension.ToLower()) { case ".mdl": { pt = sprViewer.SPRItem.PIC_TYPE.MDL; break; } case ".mtl": { pt = sprViewer.SPRItem.PIC_TYPE.MTL; break; } case ".mesh": { pt = sprViewer.SPRItem.PIC_TYPE.MESH; break; } case ".ani": { pt = sprViewer.SPRItem.PIC_TYPE.ANI; break; } case ".tani": { pt = sprViewer.SPRItem.PIC_TYPE.ANI; break; } case ".spr": { pt = sprViewer.SPRItem.PIC_TYPE.NULL; break; } } sprViewer.SPRItem si; if (pt != sprViewer.SPRItem.PIC_TYPE.NULL) { si = new sprViewer.SPRItem(f.FullName, pt, m_engine); } else { si = new sprViewer.SPRItem(f.FullName); } //check cache if (File.Exists(si.tgaFileName + ".BMP") && f.LastWriteTime.ToString() == sprViewer.IniIO.IniReadValue("cache", "time", si.tgaFileName + "_tb.ini")) { Image img = new Bitmap(si.tgaFileName + ".BMP"); imageList1.Images.Add(f.FullName, img); } else { int ind = si.TGAList.Count / 2; ind = ind == 0 ? 1 : ind; if (ind <= si.TGAList.Count) { string file = si.TGAList[ind.ToString()].ToString(); if (File.Exists(file)) { try { Image img = Image.FromFile(file); Image imgsmall = img.GetThumbnailImage(48, 48, null, IntPtr.Zero); imgsmall.Save(si.tgaFileName + ".BMP"); imageList1.Images.Add(f.FullName, imgsmall); sprViewer.IniIO.IniWriteValue("cache", "time", f.LastWriteTime.ToString(), si.tgaFileName + "_tb.ini"); } catch (System.Exception) { } } } } } }
private void LoadNodeDir(TreeNode node) { if (!Directory.Exists(((tree_tag)node.Tag).strPath)) { return; } Control ctrl_parent = lv1.Parent; ctrl_parent.Controls.Remove(lv1); if (((tree_tag)node.Tag).listv != null) { lv1 = ((tree_tag)node.Tag).listv; ctrl_parent.Controls.Add(lv1); lv1.Enabled = true; lv1.Visible = true; lv1.Select(); autoSelect(lv1); return; } fl.Show(); fl.Enabled = false; tv1.Enabled = false; lv1 = new ListView(); lv1.SelectedIndexChanged += new System.EventHandler(lv1_SelectedIndexChanged); lv1.DoubleClick += new EventHandler(lv1_DoubleClick); lv1.LargeImageList = imageList1; lv1.Dock = DockStyle.Fill; lv1.MultiSelect = false; ctrl_parent.Controls.Add(lv1); //lv1.Clear(); DirectoryInfo di = new DirectoryInfo(((tree_tag)node.Tag).strPath); fl.pbar.Maximum = di.GetFiles().Length; fl.pbar.Value = 0; ListView.ListViewItemCollection lvc = new ListView.ListViewItemCollection(lv1); lv1.Visible = false; lv2.Visible = true; if (this.showFolder == true) { string stroutout = string.Empty; foreach (DirectoryInfo d in di.GetDirectories()) { if (d.Name == ".svn" || d.Name == "Texture") { continue; } Application.DoEvents(); fl.label1.Text = d.FullName; if (imageList1.Images.ContainsKey(d.FullName)) { lvc.Add(d.Name, d.FullName).Tag = "folder"; continue; } Image imgFolder = imageList3.Images["folder.bmp"]; FileInfo[] files = d.GetFiles(this.strFolderPreviewFilter); if (files.Length == 0) { DirectoryInfo[] d111 = d.GetDirectories("模型"); if (d111.Length > 0) { files = d111[0].GetFiles(this.strFolderPreviewFilter); } } // if (files.Length == 0) //普通目录 { imageList1.Images.Add(d.FullName, imgFolder); lvc.Add(d.Name, d.FullName).Tag = "folder"; continue; } Debug.WriteLine(files[0].FullName); stroutout += files[0].FullName + "\r\n"; sprViewer.SPRItem si = new sprViewer.SPRItem(files[0].FullName, sprViewer.SPRItem.PIC_TYPE.MDL, m_engine); //check cache if (File.Exists(si.tgaFileName + "!.BMP") && d.LastWriteTime.ToString() == sprViewer.IniIO.IniReadValue("cache", "time", si.tgaFileName + "_tb.ini")) { Image img = new Bitmap(si.tgaFileName + "!.BMP"); imageList1.Images.Add(d.FullName, img); } else { int ind = si.TGAList.Count / 2; ind = ind == 0 ? 1 : ind; string strFile = si.TGAList[ind.ToString()].ToString(); if (File.Exists(strFile)) { Image img = Image.FromFile(strFile); Image imgsmall = img.GetThumbnailImage(80, 80, null, IntPtr.Zero); //imgsmall.Save(@"C:\Documents and Settings\kuangsihao\桌面\newtools\_cache\mdl\folder.bmp"); Image imgCombo = new Bitmap(imgFolder); Graphics g = Graphics.FromImage(imgCombo); //g.DrawImage(imgsmall, new Point(0, 0)); g.DrawImage(imgsmall, new Rectangle(6, 8, imgsmall.Width, imgsmall.Height)); //g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height)); imgCombo.Save(si.tgaFileName + "!.BMP"); imageList1.Images.Add(d.FullName, imgCombo); sprViewer.IniIO.IniWriteValue("cache", "time", d.LastWriteTime.ToString(), si.tgaFileName + "_tb.ini"); } } ListViewItem lvi = lvc.Add(d.Name, d.FullName); lvi.Tag = "folder"; } } foreach (FileInfo f in di.GetFiles()) { Application.DoEvents(); fl.pbar.Value++; fl.label1.Text = f.FullName; if (strFilter.IndexOf(";" + f.Extension.ToLower() + ";") == -1) { continue; } if (imageList1.Images.ContainsKey(f.FullName)) { lvc.Add(f.Name, f.FullName).Tag = "file"; continue; } if (!multi_load) { sprViewer.SPRItem.PIC_TYPE pt = sprViewer.SPRItem.PIC_TYPE.NULL; switch (f.Extension.ToLower()) { case ".mdl": { pt = sprViewer.SPRItem.PIC_TYPE.MDL; break; } case ".mtl": { pt = sprViewer.SPRItem.PIC_TYPE.MTL; break; } case ".mesh": { pt = sprViewer.SPRItem.PIC_TYPE.MESH; break; } case ".ani": { pt = sprViewer.SPRItem.PIC_TYPE.ANI; break; } case ".tani": { pt = sprViewer.SPRItem.PIC_TYPE.ANI; break; } case ".spr": { pt = sprViewer.SPRItem.PIC_TYPE.NULL; break; } } sprViewer.SPRItem si; if (pt != sprViewer.SPRItem.PIC_TYPE.NULL) { si = new sprViewer.SPRItem(f.FullName, pt, m_engine, true); } else { si = new sprViewer.SPRItem(f.FullName); } //check cache if (File.Exists(si.tgaFileName + ".BMP") && f.LastWriteTime.ToString() == sprViewer.IniIO.IniReadValue("cache", "time", si.tgaFileName + "_tb.ini")) { Image img = new Bitmap(si.tgaFileName + ".BMP"); imageList1.Images.Add(f.FullName, img); } else { int ind = si.TGAList.Count / 2; ind = ind == 0 ? 1 : ind; if (ind <= si.TGAList.Count) { string file = si.TGAList[ind.ToString()].ToString(); if (File.Exists(file)) { Image img = Image.FromFile(file); Image imgsmall = img.GetThumbnailImage(48, 48, null, IntPtr.Zero); imgsmall.Save(si.tgaFileName + ".BMP"); imageList1.Images.Add(f.FullName, imgsmall); sprViewer.IniIO.IniWriteValue("cache", "time", f.LastWriteTime.ToString(), si.tgaFileName + "_tb.ini"); } } } } ListViewItem lvi = lvc.Add(f.Name, f.FullName); lvi.Tag = "file"; } if (multi_load) { m_thread = new System.Threading.Thread(new System.Threading.ThreadStart(ThreadProc)); m_thread.Start(); } ((tree_tag)node.Tag).listv = lv1; //清多于nQueMax个ListView的缓存 tag_que.Enqueue((tree_tag)node.Tag); while (tag_que.Count > nQueMax) { tree_tag tt = tag_que.Dequeue(); tt.listv = null; } fl.Hide(); tv1.Enabled = true; lv1.Visible = true; lv2.Visible = false; lv1.Select(); autoSelect(lv1); OldLVC.Clear(); }
public void ThreadProc() { if (m_threadExit) { return; } TreeView.CheckForIllegalCrossThreadCalls = false; DirectoryInfo di = new DirectoryInfo(((tree_tag)this.tv1.SelectedNode.Tag).strPath); ListView.ListViewItemCollection lvc = new ListView.ListViewItemCollection(this.lv1); foreach (FileInfo f in di.GetFiles()) { if (m_threadExit) { return; } Application.DoEvents(); fl.pbar.Value++; fl.label1.Text = f.FullName; if (strFilter.IndexOf(";" + f.Extension.ToLower() + ";") == -1) { continue; } if (imageList1.Images.ContainsKey(f.FullName)) { continue; } sprViewer.SPRItem.PIC_TYPE pt = sprViewer.SPRItem.PIC_TYPE.NULL; switch (f.Extension.ToLower()) { case ".mdl": { pt = sprViewer.SPRItem.PIC_TYPE.MDL; break; } case ".mtl": { pt = sprViewer.SPRItem.PIC_TYPE.MTL; break; } case ".mesh": { pt = sprViewer.SPRItem.PIC_TYPE.MESH; break; } case ".ani": { pt = sprViewer.SPRItem.PIC_TYPE.ANI; break; } case ".tani": { pt = sprViewer.SPRItem.PIC_TYPE.ANI; break; } case ".spr": { pt = sprViewer.SPRItem.PIC_TYPE.NULL; break; } } sprViewer.SPRItem si; if (pt != sprViewer.SPRItem.PIC_TYPE.NULL) { si = new sprViewer.SPRItem(f.FullName, pt, m_engine); } else { si = new sprViewer.SPRItem(f.FullName); } //check cache if(File.Exists(si.tgaFileName + ".BMP") && f.LastWriteTime.ToString() == sprViewer.IniIO.IniReadValue("cache","time",si.tgaFileName + "_tb.ini")) { Image img = new Bitmap(si.tgaFileName + ".BMP"); imageList1.Images.Add(f.FullName, img); } else { int ind = si.TGAList.Count / 2 ; ind = ind == 0 ? 1 : ind; if (ind <= si.TGAList.Count) { string file = si.TGAList[ind.ToString()].ToString(); if (File.Exists(file)) { try { Image img = Image.FromFile(file); Image imgsmall = img.GetThumbnailImage(48, 48, null, IntPtr.Zero); imgsmall.Save(si.tgaFileName + ".BMP"); imageList1.Images.Add(f.FullName, imgsmall); sprViewer.IniIO.IniWriteValue("cache", "time", f.LastWriteTime.ToString(), si.tgaFileName + "_tb.ini"); } catch (System.Exception ) { } } } } } }
private void LoadNodeDir(TreeNode node) { if (!Directory.Exists(((tree_tag)node.Tag).strPath)) { return; } Control ctrl_parent = lv1.Parent; ctrl_parent.Controls.Remove(lv1); if (((tree_tag)node.Tag).listv != null) { lv1 = ((tree_tag)node.Tag).listv; ctrl_parent.Controls.Add(lv1); lv1.Enabled = true; lv1.Visible = true; lv1.Select(); autoSelect(lv1); return; } fl.Show(); fl.Enabled = false; tv1.Enabled = false; lv1 = new ListView(); lv1.SelectedIndexChanged += new System.EventHandler(lv1_SelectedIndexChanged); lv1.DoubleClick += new EventHandler(lv1_DoubleClick); lv1.LargeImageList = imageList1; lv1.Dock = DockStyle.Fill; lv1.MultiSelect = false; ctrl_parent.Controls.Add(lv1); //lv1.Clear(); DirectoryInfo di = new DirectoryInfo(((tree_tag)node.Tag).strPath); fl.pbar.Maximum = di.GetFiles().Length; fl.pbar.Value = 0; ListView.ListViewItemCollection lvc = new ListView.ListViewItemCollection(lv1); lv1.Visible = false; lv2.Visible = true; if(this.showFolder == true) { string stroutout = string.Empty; foreach (DirectoryInfo d in di.GetDirectories()) { if (d.Name == ".svn" || d.Name == "Texture") continue; Application.DoEvents(); fl.label1.Text = d.FullName; if (imageList1.Images.ContainsKey(d.FullName)) { lvc.Add(d.Name, d.FullName).Tag = "folder"; continue; } Image imgFolder = imageList3.Images["folder.bmp"]; FileInfo[] files = d.GetFiles(this.strFolderPreviewFilter); if(files.Length == 0) { DirectoryInfo[] d111 = d.GetDirectories("模型"); if (d111.Length > 0) files = d111[0].GetFiles(this.strFolderPreviewFilter); } // if(files.Length == 0) //普通目录 { imageList1.Images.Add(d.FullName, imgFolder); lvc.Add(d.Name, d.FullName).Tag = "folder"; continue; } Debug.WriteLine(files[0].FullName); stroutout += files[0].FullName + "\r\n"; sprViewer.SPRItem si = new sprViewer.SPRItem(files[0].FullName, sprViewer.SPRItem.PIC_TYPE.MDL, m_engine); //check cache if (File.Exists(si.tgaFileName + "!.BMP") && d.LastWriteTime.ToString() == sprViewer.IniIO.IniReadValue("cache", "time", si.tgaFileName + "_tb.ini")) { Image img = new Bitmap(si.tgaFileName + "!.BMP"); imageList1.Images.Add(d.FullName, img); } else { int ind = si.TGAList.Count / 2; ind = ind == 0 ? 1 : ind; string strFile = si.TGAList[ind.ToString()].ToString(); if (File.Exists(strFile)) { Image img = Image.FromFile(strFile); Image imgsmall = img.GetThumbnailImage(80, 80, null, IntPtr.Zero); //imgsmall.Save(@"C:\Documents and Settings\kuangsihao\桌面\newtools\_cache\mdl\folder.bmp"); Image imgCombo = new Bitmap(imgFolder); Graphics g = Graphics.FromImage(imgCombo); //g.DrawImage(imgsmall, new Point(0, 0)); g.DrawImage(imgsmall, new Rectangle(6, 8, imgsmall.Width, imgsmall.Height)); //g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height)); imgCombo.Save(si.tgaFileName + "!.BMP"); imageList1.Images.Add(d.FullName, imgCombo); sprViewer.IniIO.IniWriteValue("cache", "time", d.LastWriteTime.ToString(), si.tgaFileName + "_tb.ini"); } } ListViewItem lvi = lvc.Add(d.Name, d.FullName); lvi.Tag = "folder"; } } foreach (FileInfo f in di.GetFiles()) { Application.DoEvents(); fl.pbar.Value++; fl.label1.Text = f.FullName; if (strFilter.IndexOf(";" + f.Extension.ToLower() + ";") == -1) { continue; } if (imageList1.Images.ContainsKey(f.FullName)) { lvc.Add(f.Name, f.FullName).Tag = "file"; continue; } if (!multi_load) { sprViewer.SPRItem.PIC_TYPE pt = sprViewer.SPRItem.PIC_TYPE.NULL; switch (f.Extension.ToLower()) { case ".mdl": { pt = sprViewer.SPRItem.PIC_TYPE.MDL; break; } case ".mtl": { pt = sprViewer.SPRItem.PIC_TYPE.MTL; break; } case ".mesh": { pt = sprViewer.SPRItem.PIC_TYPE.MESH; break; } case ".ani": { pt = sprViewer.SPRItem.PIC_TYPE.ANI; break; } case ".tani": { pt = sprViewer.SPRItem.PIC_TYPE.ANI; break; } case ".spr": { pt = sprViewer.SPRItem.PIC_TYPE.NULL; break; } } sprViewer.SPRItem si; if (pt != sprViewer.SPRItem.PIC_TYPE.NULL) { si = new sprViewer.SPRItem(f.FullName, pt, m_engine, true); } else { si = new sprViewer.SPRItem(f.FullName); } //check cache if (File.Exists(si.tgaFileName + ".BMP") && f.LastWriteTime.ToString() == sprViewer.IniIO.IniReadValue("cache", "time", si.tgaFileName + "_tb.ini")) { Image img = new Bitmap(si.tgaFileName + ".BMP"); imageList1.Images.Add(f.FullName, img); } else { int ind = si.TGAList.Count / 2; ind = ind == 0 ? 1 : ind; if (ind <= si.TGAList.Count) { string file = si.TGAList[ind.ToString()].ToString(); if (File.Exists(file)) { Image img = Image.FromFile(file); Image imgsmall = img.GetThumbnailImage(48, 48, null, IntPtr.Zero); imgsmall.Save(si.tgaFileName + ".BMP"); imageList1.Images.Add(f.FullName, imgsmall); sprViewer.IniIO.IniWriteValue("cache", "time", f.LastWriteTime.ToString(), si.tgaFileName + "_tb.ini"); } } } } ListViewItem lvi = lvc.Add(f.Name, f.FullName); lvi.Tag = "file"; } if (multi_load) { m_thread = new System.Threading.Thread(new System.Threading.ThreadStart(ThreadProc)); m_thread.Start(); } ((tree_tag)node.Tag).listv = lv1; //清多于nQueMax个ListView的缓存 tag_que.Enqueue((tree_tag)node.Tag); while (tag_que.Count > nQueMax) { tree_tag tt = tag_que.Dequeue(); tt.listv = null; } fl.Hide(); tv1.Enabled = true; lv1.Visible = true; lv2.Visible = false; lv1.Select(); autoSelect(lv1); OldLVC.Clear(); }