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));
        }
        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);
            }
        }
Esempio n. 3
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.
            }
        }
        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");
            }
        }
 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;
         }
     }
 }
Esempio n. 6
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();
        }
        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();
            }
        }