private void OfflinePageRemove(PageBox box) { string fileName = box.name.Text.Substring(2, box.name.Text.Length - 3); box.pic.Image = null; GC.Collect(); GC.WaitForPendingFinalizers(); box.name.Dispose(); box.pic.Dispose(); File.Delete(setupPath + "OfflinePage\\" + fileName + ".jpg"); File.Delete(setupPath + "OfflinePage\\" + fileName + ".html"); }
// 즐겨찾기/탭 묶음/오프라인 파일 및 컨트롤 삭제 private void FavoriteRemove(PageBox box) { string fileName = box.name.Text.Substring(0, box.name.Text.Length - 1); box.pic.Image = null; GC.Collect(); GC.WaitForPendingFinalizers(); box.name.Dispose(); box.pic.Dispose(); File.Delete(setupPath + "Favorite\\" + fileName + ".jpg"); File.Delete(setupPath + "Favorite\\" + fileName + ".txt"); }
private void tsmiAddBookmark_Click(object sender, EventArgs e) { frmAddFavorite frm = new frmAddFavorite(); WebBrowser wb = (WebBrowser)tabBrowser.SelectedTab.Controls[0]; // 즐겨찾기 등록 창 텍스트 상자에 제목 입력 if (wb.DocumentTitle != "") { frm.txtNameText = wb.DocumentTitle; } // 즐겨찾기 등록 창 텍스트 상자에 URL 입력 if (txtUrl.Text != "") { frm.txtUrlText = txtUrl.Text; } // 확인버튼을 누르면 패널에 PictureBox, Label 동적 생성 if (frm.ShowDialog() == DialogResult.OK) { try { PageBox box = new PageBox(); Bitmap img = Screenshot.Create(wb); img.Save(setupPath + "Favorite\\" + frm.txtNameText + ".jpg"); File.WriteAllText(setupPath + "Favorite\\" + frm.txtNameText + ".txt", frm.txtUrlText); box.pic.Image = Image.FromFile(setupPath + "Favorite\\" + frm.txtNameText + ".jpg"); box.pic.Tag = File.ReadAllText(setupPath + "Favorite\\" + frm.txtNameText + ".txt"); box.name.Text = Path.GetFileNameWithoutExtension(setupPath + "Favorite\\" + frm.txtNameText + ".jpg"); if (favoriteCount % 2 == 0) { box.pic.Location = new Point(20 + favoriteCount / 2 * 380, 80); } else { box.pic.Location = new Point(20 + favoriteCount / 2 * 380, 380); } box.name.Location = new Point(box.pic.Location.X, box.pic.Location.Y - 25); box.pic.Click += new EventHandler(favoriteBox_Click); // 이미지 클릭 시 페이지 이동 핸들러 발동 box.name.MouseEnter += new EventHandler(boxName_MouseEnter); box.name.MouseLeave += new EventHandler(boxName_MouseLeave); box.name.Click += delegate { FavoriteRemove(box); }; // 이름 누르면 삭제 favoriteCount++; pnlFavorite.Controls.Add(box.name); pnlFavorite.Controls.Add(box.pic); } catch { MessageBox.Show("저장에 실패했습니다. 이름을 확인하세요."); } } }
private void tsmiSaveOffline_Click(object sender, EventArgs e) { frmSaveOffline frm = new frmSaveOffline(); WebBrowser wb = (WebBrowser)tabBrowser.SelectedTab.Controls[0]; // 오프라인 등록 창 텍스트 상자에 제목 입력 if (wb.DocumentTitle != "") { frm.txtNameText = wb.DocumentTitle; } // 확인버튼을 누르면 패널에 PictureBox, Label 동적 생성 if (frm.ShowDialog() == DialogResult.OK) { try { PageBox box = new PageBox(); Bitmap img = Screenshot.Create(wb); img.Save(setupPath + "OfflinePage\\" + frm.txtNameText + ".jpg"); box.pic.Image = img; box.pic.Tag = setupPath + "OfflinePage\\" + frm.txtNameText + ".html"; box.name.Text = "☻ " + frm.txtNameText; if (offlineCount % 2 == 0) { box.pic.Location = new Point(20 + offlineCount / 2 * 380, 80); } else { box.pic.Location = new Point(20 + offlineCount / 2 * 380, 380); } box.name.Location = new Point(box.pic.Location.X, box.pic.Location.Y - 25); box.pic.Click += new EventHandler(offlineBox_Click); // 이미지 클릭 시 페이지 이동 핸들러 발동 box.name.MouseEnter += new EventHandler(boxName_MouseEnter); box.name.MouseLeave += new EventHandler(boxName_MouseLeave); box.name.Click += delegate { OfflinePageRemove(box); }; // 이름 누르면 삭제 offlineCount++; pnlOffline.Controls.Add(box.name); pnlOffline.Controls.Add(box.pic); File.WriteAllText(setupPath + "OfflinePage\\" + frm.txtNameText + ".html", wb.Document.Body.Parent.OuterHtml, Encoding.GetEncoding(wb.Document.Encoding)); } catch { MessageBox.Show("저장에 실패했습니다. 이름을 확인하세요."); } } }
public frmGoraniBrowser() { regeditIE11(); InitializeComponent(); wbBrowser.ScriptErrorsSuppressed = true; // 자바 스크립트 오류 창 안뜨게하기 DirectoryInfo di = new DirectoryInfo(setupPath); // Setup 폴더 없으면 생성 if (di.Exists == false) { di.Create(); di = new DirectoryInfo(setupPath + "Favorite\\"); di.Create(); di = new DirectoryInfo(setupPath + "OfflinePage\\"); di.Create(); di = new DirectoryInfo(setupPath + "TabBundle\\"); di.Create(); File.Create(setupPath + "history.txt"); File.WriteAllText(setupPath + "homepage.txt", "https://www.google.com/"); // 첫 홈페이지 구글로 초기화 } // Setup 폴더가 존재하면 else { // 저장된 즐겨찾기 목록 가져오기 di = new DirectoryInfo(setupPath + "Favorite\\"); foreach (FileInfo fi in di.GetFiles()) { if (fi.Extension.ToLower() == ".jpg") { PageBox box = new PageBox(); // PageBox 이미지 PictureBox 설정 box.pic.Image = Image.FromFile(fi.FullName); // 저장된 이미지 가져오기 box.pic.Tag = File.ReadAllText(setupPath + "Favorite\\" + fi.Name.Substring(0, fi.Name.Length - 4) + ".txt"); // PictureBox 태그로 URL 저장 // PageBox 이름 Label 설정 box.name.Text = fi.Name.Substring(0, fi.Name.Length - 4); // 확장자 제외한 파일 이름으로 PageBox 이름 텍스트 설정 // 정렬 if (favoriteCount % 2 == 0) { box.pic.Location = new Point(20 + favoriteCount / 2 * 380, 80); } else { box.pic.Location = new Point(20 + favoriteCount / 2 * 380, 380); } box.name.Location = new Point(box.pic.Location.X, box.pic.Location.Y - 25); box.pic.Click += new EventHandler(favoriteBox_Click); // 이미지 클릭 시 페이지 이동 핸들러 발동 box.name.MouseEnter += new EventHandler(boxName_MouseEnter); box.name.MouseLeave += new EventHandler(boxName_MouseLeave); box.name.Click += delegate { FavoriteRemove(box); }; // 이름 누르면 삭제 favoriteCount++; // 컨트롤에 추가 pnlFavorite.Controls.Add(box.name); pnlFavorite.Controls.Add(box.pic); } } // 저장된 탭묶음 목록 가져오기 di = new DirectoryInfo(setupPath + "TabBundle\\"); foreach (FileInfo fi in di.GetFiles()) { if (fi.Name.Length >= 7 && fi.Name.Substring(fi.Name.Length - 7, 3) == "URL") { TabBox box = new TabBox(); box.name.Text = fi.Name.Substring(0, fi.Name.Length - 7); box.list.Text = File.ReadAllText(setupPath + "TabBundle\\" + fi.Name.Substring(0, fi.Name.Length - 7) + ".txt"); box.list.Tag = File.ReadAllText(fi.FullName); if (TabBundleCount % 2 == 0) { box.back1.Location = new Point(30 + TabBundleCount / 2 * 380, 70); box.back2.Location = new Point(25 + TabBundleCount / 2 * 380, 75); box.list.Location = new Point(20 + TabBundleCount / 2 * 380, 105); } else { box.back1.Location = new Point(30 + TabBundleCount / 2 * 380, 370); box.back2.Location = new Point(25 + TabBundleCount / 2 * 380, 375); box.list.Location = new Point(20 + TabBundleCount / 2 * 380, 405); } box.name.Location = new Point(box.list.Location.X, box.list.Location.Y - 25); box.list.Click += new EventHandler(tabBundleBox_Click); // 이미지 클릭 시 페이지 이동 핸들러 발동 box.name.MouseEnter += new EventHandler(boxName_MouseEnter); box.name.MouseLeave += new EventHandler(boxName_MouseLeave); box.name.Click += delegate { TabBundleRemove(box); }; // 이름 누르면 삭제 TabBundleCount++; pnlTabBundle.Controls.Add(box.list); pnlTabBundle.Controls.Add(box.name); pnlTabBundle.Controls.Add(box.back2); pnlTabBundle.Controls.Add(box.back1); } } // 저장된 오프라인페이지 목록 가져오기 di = new DirectoryInfo(setupPath + "OfflinePage\\"); foreach (FileInfo fi in di.GetFiles()) { if (fi.Extension.ToLower() == ".jpg") { PageBox box = new PageBox(); // PageBox의 이미지 PictureBox 설정 box.pic.Image = Image.FromFile(fi.FullName); // 저장된 이미지 가져오기 box.pic.Tag = fi.FullName.Substring(0, fi.FullName.Length - 4) + ".html"; // PictureBox 태그로 html 파일 경로 저장 // PageBox의 이름 Label 설정 box.name.Text = "☻ " + fi.Name.Substring(0, fi.Name.Length - 4); // 확장자 제외한 파일 이름으로 PageBox 이름 텍스트 설정 // 정렬 if (offlineCount % 2 == 0) { box.pic.Location = new Point(20 + offlineCount / 2 * 380, 80); } else { box.pic.Location = new Point(20 + offlineCount / 2 * 380, 380); } box.name.Location = new Point(box.pic.Location.X, box.pic.Location.Y - 25); box.pic.Click += new EventHandler(offlineBox_Click); // 이미지 클릭 시 페이지 이동 핸들러 발동 box.name.MouseEnter += new EventHandler(boxName_MouseEnter); box.name.MouseLeave += new EventHandler(boxName_MouseLeave); box.name.Click += delegate { OfflinePageRemove(box); }; // 이름 누르면 삭제 offlineCount++; pnlOffline.Controls.Add(box.name); pnlOffline.Controls.Add(box.pic); } } // 저장된 방문기록 목록 가져오기 var history = File.ReadAllLines(setupPath + "history.txt"); for (int i = 0; i + lvwHistory.Columns.Count - 1 < history.Length; i += lvwHistory.Columns.Count) { lvwHistory.Items.Add(new ListViewItem(new[] { history[i], history[i + 1], history[i + 2] })); } } homepage = File.ReadAllText(setupPath + "homepage.txt"); // homepage.txt 내용으로 homepage 설정 GoWebSite(homepage); AddHistory(); }