コード例 #1
0
        public static bool DownloadWebsiteSnapshot(string sUrl, string sDest)
        {
            if (!BookmarkBucketCore.looksLikeAUrl(sUrl))
            {
                throw new BookmarkBucketException("invalid url");
            }
            string sOptions = " \"--url=" + sUrl + "\"";

            sOptions += " \"--out=" + sDest + "\"";
            sOptions += " --max-wait=40000 --delay=1000 --java=off --plugins=off";
            System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();
            //Environment.
            info.FileName = Program.GetExeDirectory() + "\\CutyCapt.exe";
            if (!File.Exists(info.FileName))
            {
                throw new BookmarkBucketException("Cannot find " + info.FileName);
            }
            info.Arguments       = sOptions;
            info.UseShellExecute = false;
            info.Verb            = "open";
            info.CreateNoWindow  = true;
            System.Diagnostics.Process p = System.Diagnostics.Process.Start(info);
            p.WaitForExit(45 * 1000);
            return(File.Exists(sDest));
        }
コード例 #2
0
        public void TopCreateOneShortcut(bool bJpegAlreadyExists)
        {
            string sUrl = InputBoxForm.GetStrInput("Enter URL:", "http://example");

            if (!BookmarkBucketCore.looksLikeAUrl(sUrl))
            {
                return;
            }

            if (bJpegAlreadyExists)
            {
                string sInputJpeg = ImageHelper.GetOpenString("jpeg", "Select a jpeg:");
                if (sInputJpeg == null || !File.Exists(sInputJpeg))
                {
                    return;
                }
                BookmarkBucketCore.StripAllExifData(sInputJpeg);
                BookmarkBucketCore.SetExifData(sInputJpeg, sUrl, Path.GetFileNameWithoutExtension(sInputJpeg));
            }
            else
            {
                string sOutJpeg = ImageHelper.GetSaveString("jpeg", "Save jpeg to:");
                if (sOutJpeg == null)
                {
                    return;
                }
                string             sDir = Path.GetDirectoryName(sOutJpeg);
                BookmarkBucketItem item = new BookmarkBucketItem {
                    sFile = Path.GetFileNameWithoutExtension(sOutJpeg), sUrl = sUrl
                };
                ModelItemToJpeg(item, sDir);
            }
        }
コード例 #3
0
        private void ModelItemToJpeg(BookmarkBucketItem item, string sDir)
        {
            // If the webpage cannot be loaded, we want to create a .html and .jpeg anyways.
            // 1) save html
            string sHtml    = sDir + "\\" + item.GetNameWithoutExtension() + ".html";
            bool   bGotHtml = BookmarkBucketImplementation.DownloadFile(item.sUrl, sHtml);

            File.AppendAllText(sHtml, strHtmlStamp + item.sUrl + "-->"); // will create file.

            // 2) save png screenshot
            string sPng       = sDir + "\\" + item.GetNameWithoutExtension() + ".png";
            bool   bSucceeded = BookmarkBucketImplementation.DownloadWebsiteSnapshot(item.sUrl, sPng);

            if (!bSucceeded)
            {
                using (Bitmap b = ImageHelper.GetBlankBitmap(300, 300)) { b.Save(sPng); }
            }

            // 3) resize and convert png to jpeg
            string sJpeg = sDir + "\\" + item.GetNameWithoutExtension() + ".jpeg";

            ImageHelper.ResizeAndTruncateAndSaveImage(sPng, sJpeg, 400, 300, 0.5f, 84, false);
            File.Delete(sPng);
            if (!File.Exists(sJpeg))
            {
                throw new BookmarkBucketException("Jpeg file expected to be created for '" + item.sFile + "', but was not found");
            }

            // 4) write exif info to jpeg
            BookmarkBucketCore.SetExifData(sJpeg, item.sUrl, item.GetNameWithoutExtension());
        }
コード例 #4
0
        private void ConvertOldToNewWithoutRedownloading()
        {
            string sDir = InputBoxForm.GetStrInput("All from this directory:", "c:\\example");

            if (sDir == null || !Directory.Exists(sDir))
            {
                MessageBox.Show("Not a valid directory."); return;
            }

            DirectoryInfo di = new DirectoryInfo(sDir);

            FileInfo[] rgFiles = di.GetFiles("*.jpg");
            foreach (FileInfo fi in rgFiles)
            {
                string sNewname = Path.GetFileNameWithoutExtension(fi.Name.Replace("555 ", "")) + ".png";
                if (File.Exists(sDir + "\\" + sNewname))
                {
                    throw new BookmarkBucketException("exists png" + fi.Name);
                }
                File.Move(sDir + "\\" + fi.Name, sDir + "\\" + sNewname);
            }

            // set the exifs...
            FileInfo[] rgFilesPng = di.GetFiles("*.png");
            foreach (FileInfo fi in rgFilesPng)
            {
                string sOldUrl = BookmarkBucketCore.GetExifData(fi.FullName, "Comment");
                if (!BookmarkBucketCore.looksLikeAUrl(sOldUrl))
                {
                    throw new BookmarkBucketException("couldnot read url" + fi.Name);
                }

                // convert it to a jpg.
                string sJpeg = sDir + "\\" + Path.GetFileNameWithoutExtension(fi.Name) + ".jpeg";
                using (Bitmap b = new Bitmap(fi.FullName))
                {
                    ImageHelper.BitmapSaveJpegQuality(b, sJpeg, 85);
                }
                if (!File.Exists(sJpeg))
                {
                    throw new BookmarkBucketException("no jpeg created?");
                }
                File.Delete(fi.FullName);

                BookmarkBucketCore.StripAllExifData(sJpeg);
                BookmarkBucketCore.SetExifData(sJpeg, sOldUrl, Path.GetFileNameWithoutExtension(fi.Name));

                // download the htm!
                string sHtmlName = sDir + "\\" + Path.GetFileNameWithoutExtension(fi.Name) + ".html";
                if (File.Exists(sHtmlName))
                {
                    throw new BookmarkBucketException("exists html" + fi.Name);
                }
                BookmarkBucketImplementation.DownloadFile(sOldUrl, sHtmlName);
                File.AppendAllText(sHtmlName, strHtmlStamp + sOldUrl + "-->"); // will create file.
            }
        }
コード例 #5
0
        public void TopCreateManualShortcut(string sFilename)
        {
            string sUrl = InputBoxForm.GetStrInput("Stamp URL on a file - Enter URL:", "http://example");

            if (!BookmarkBucketCore.looksLikeAUrl(sUrl))
            {
                return;
            }
            if (sFilename.ToLowerInvariant().EndsWith(".html"))
            {
                File.AppendAllText(sFilename, strHtmlStamp + sUrl + "-->");
            }
            else if (sFilename.ToLowerInvariant().EndsWith(".jpeg"))
            {
                BookmarkBucketCore.StripAllExifData(sFilename);
                BookmarkBucketCore.SetExifData(sFilename, sUrl, Path.GetFileNameWithoutExtension(sFilename));
            }
            else
            {
                MessageBox.Show("Try a .html or .jpeg file");
            }
        }
コード例 #6
0
 public void TopOpenWebpagesAssociatedWithJpegs(string[] files)
 {
     if (files == null || files.Length == 0)
     {
         return;
     }
     foreach (string file in files)
     {
         if (file.ToLowerInvariant().EndsWith(".jpeg"))
         {
             string sUrl = BookmarkBucketCore.GetExifDataUrl(file);
             if (sUrl == null || sUrl.Length == 0)
             {
                 MessageBox.Show("Url does not appear to be valid."); return;
             }
             BookmarkBucketCore.LaunchWebpage(sUrl);
         }
         else if (file.ToLowerInvariant().EndsWith(".html"))
         {
             string sAll  = File.ReadAllText(file);
             int    index = sAll.IndexOf(strHtmlStamp, StringComparison.InvariantCulture);
             if (index != -1)
             {
                 string strRest = sAll.Substring(index + strHtmlStamp.Length).Trim().Replace("-->", "");
                 if (BookmarkBucketCore.looksLikeAUrl(strRest) && !strRest.Contains("<") && !strRest.Contains(">") && strRest.Length < 200)
                 {
                     BookmarkBucketCore.LaunchWebpage(strRest);
                 }
             }
             sAll = null;
         }
         else
         {
             MessageBox.Show("Please use only .jpeg files, as created by BookmarkBucket."); return;
         }
     }
 }
コード例 #7
0
        private BookmarkBucketObjectModel JpegFilesToModel(string sDir)
        {
            if (!Directory.Exists(sDir))
            {
                throw new BookmarkBucketException("Dir does not exist");
            }
            BookmarkBucketObjectModel model = new BookmarkBucketObjectModel();
            DirectoryInfo             di    = new DirectoryInfo(sDir);

            FileInfo[] rgFiles = di.GetFiles("*.JPEG");
            foreach (FileInfo fi in rgFiles)
            {
                string sUrl = BookmarkBucketCore.GetExifDataUrl(sDir + "\\" + fi.Name);
                if (sUrl == null || sUrl.Length == 0)
                {
                    throw new BookmarkBucketException("Url is null in " + fi.Name);
                }

                model.list.Add(new BookmarkBucketItem {
                    sFile = Path.GetFileNameWithoutExtension(fi.Name), sUrl = sUrl
                });
            }
            return(model);
        }
コード例 #8
0
        public void TopRunUnitTests()
        {
            //string sTestDir = @"C:\Users\diamond\Desktop\-frommain\delldev\bookmarkbuckets\bookmarkbuckets_cs\bookmarkbucket\bookmarkbucket_console\bookmarkbucket_ui\test";
            //string s1 = BookmarkBucketCore.GetExifDataSoftware(sTestDir + "\\k.jpeg");
            //string s2 = BookmarkBucketCore.GetExifDataTitle(sTestDir + "\\k.jpeg");
            //string s3 = BookmarkBucketCore.GetExifDataUrl(sTestDir + "\\k.jpeg");
            //MessageBox.Show(String.Format("{0}\n{1}\n{2}\n", s1,s2,s3));

            // convert from old to new.
            //bool b = ThreadPool.SetMaxThreads(4, 4);
            //System.Diagnostics.Debug.Assert(b);

            DialogResult dr = MessageBox.Show("Create new jpgs?", "bb", MessageBoxButtons.YesNo);

            if (dr == DialogResult.No)
            {
                ConvertOldToNewWithoutRedownloading(); return;
            }

            string sDir = InputBoxForm.GetStrInput("All from this directory:", "c:\\example");

            if (sDir == null || !Directory.Exists(sDir))
            {
                MessageBox.Show("Not a valid directory."); return;
            }

            DirectoryInfo di = new DirectoryInfo(sDir);

            FileInfo[] rgFiles = di.GetFiles("*.jpg");
            foreach (FileInfo fi in rgFiles)
            {
                string sNewname = Path.GetFileNameWithoutExtension(fi.Name.Replace("555 ", "")) + ".png";
                if (File.Exists(sDir + "\\" + sNewname))
                {
                    throw new BookmarkBucketException("exists png" + fi.Name);
                }
                File.Move(sDir + "\\" + fi.Name, sDir + "\\" + sNewname);
            }

            // make a Model
            BookmarkBucketObjectModel model = new BookmarkBucketObjectModel();

            FileInfo[] rgFilesPng = di.GetFiles("*.png");
            foreach (FileInfo fi in rgFilesPng)
            {
                string sOldUrl = BookmarkBucketCore.GetExifData(fi.FullName, "Comment");
                if (!BookmarkBucketCore.looksLikeAUrl(sOldUrl))
                {
                    throw new BookmarkBucketException("couldnot read url" + fi.Name);
                }

                model.list.Add(new BookmarkBucketItem {
                    sFile = Path.GetFileNameWithoutExtension(fi.Name), sUrl = sOldUrl
                });
            }

            Form1.g_busy = true;
            Thread oThread = new Thread(delegate()
            {
                CallAndCatchExceptions.Call(delegate(object o)
                {
                    this.ModelToJpegs(model, sDir);
                    Form1.g_busy = false; Form1.g_status = "";
                }, null);
            });

            oThread.Start();
        }
コード例 #9
0
        private void ModelToJpegs(BookmarkBucketObjectModel obj, string sDir)
        {
            if (obj == null || obj.list.Count == 0)
            {
                return;
            }
            sDir += "\\out";
            if (Directory.Exists(sDir))
            {
                throw new BookmarkBucketException("'out' directory already exists.");
            }
            Directory.CreateDirectory(sDir);

            // first, make sure we won't overwrite files.
            foreach (BookmarkBucketItem item in obj.list)
            {
                if (item.sFile.Length == 0 || item.sUrl.Length == 0)
                {
                    throw new BookmarkBucketException("Missing url or title.");
                }
                if (!BookmarkBucketCore.looksLikeAUrl(item.sUrl))
                {
                    throw new BookmarkBucketException("invalid url");
                }
                if (File.Exists(sDir + "\\" + item.GetNameWithoutExtension() + ".jpeg"))
                {
                    throw new BookmarkBucketException("Jpeg for '" + item.GetNameWithoutExtension() + "' already exists.");
                }
                if (File.Exists(sDir + "\\" + item.GetNameWithoutExtension() + ".png"))
                {
                    throw new BookmarkBucketException("Png for '" + item.GetNameWithoutExtension() + "' already exists.");
                }
                if (File.Exists(sDir + "\\" + item.GetNameWithoutExtension() + ".html"))
                {
                    throw new BookmarkBucketException("Html for '" + item.GetNameWithoutExtension() + "' already exists.");
                }
            }
            // test write access.
            try { File.WriteAllText(sDir + "\\!!temp!!.test", "test"); }
            catch (IOException) { throw new BookmarkBucketException("Apparently no write access here..."); }
            finally { if (File.Exists(sDir + "\\!!temp!!.test"))
                      {
                          File.Delete(sDir + "\\!!temp!!.test");
                      }
            }

            // use my own threadpool instead of c#'s because I want to limit number of threads running.
            int nThreads = 4;
            ModelToJpegsParameters param = new ModelToJpegsParameters {
                iItemLatest = 0, locker = new object(), model = obj, sDir = sDir
            };

            Thread[] threads = new Thread[nThreads];
            for (int i = 0; i < nThreads; i++)
            {
                threads[i] = new Thread(new ParameterizedThreadStart(this.ModelToJpegsThread));
                threads[i].Start(param);
            }
            // wait for all threads to complete. note that obj.version will be negative if an error occurred.
            for (int i = 0; i < nThreads; i++)
            {
                threads[i].Join();
            }
        }
コード例 #10
0
 private void websiteToolStripMenuItem_Click(object sender, EventArgs e)
 {
     BookmarkBucketCore.LaunchWebpage("https://github.com/moltenform/labs_youthful_projects/");
 }