public string Pharse(string template, PhotoSession session, ICameraDevice device, string fileName, string tempfileName)
        {
            if (!File.Exists(tempfileName))
            {
                return("");
            }

            // load a bitmap
            PhotoUtils.WaitForFile(tempfileName);

            var file = tempfileName;

            if (Path.GetExtension(fileName).ToLower() == ".cr2" || Path.GetExtension(fileName).ToLower() == ".nef")
            {
                string dcraw_exe = Path.Combine(Settings.ApplicationFolder, "dcraw.exe");
                if (File.Exists(dcraw_exe))
                {
                    string thumb = Path.Combine(Path.GetTempPath(),
                                                Path.GetFileNameWithoutExtension(tempfileName) + ".thumb.jpg");
                    PhotoUtils.RunAndWait(dcraw_exe,
                                          string.Format(" -e -O \"{0}\" \"{1}\"", thumb, tempfileName));
                    if (File.Exists(thumb))
                    {
                        var res = GetBarcode(thumb, template);
                        File.Delete(thumb);
                        return(res);
                    }
                }
            }
            else
            {
                return(GetBarcode(tempfileName, template));
            }
            return(template);
        }
Exemplo n.º 2
0
        public void Execute(object parameter)
        {
            if (!ServiceProvider.Settings.SelectedBitmap.FileItem.IsRaw)
            {
                MessageBox.Show("Raw file is needed for this action");
                return;
            }
            string _infile      = ServiceProvider.Settings.SelectedBitmap.FileItem.FileName;
            string _otfile      = Path.Combine(Path.GetDirectoryName(_infile), Path.GetFileNameWithoutExtension(_infile) + ".jpg");
            string _pathtoufraw =
                Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), "ufraw",
                             "ufraw-batch.exe");

            if (File.Exists(_pathtoufraw))
            {
                if (PhotoUtils.RunAndWait(_pathtoufraw,
                                          " --wb=camera --saturation=1.2 --exposure=0 --black-point=auto --overwrite --out-type=jpg --output=" +
                                          _otfile + " " + _infile))
                {
                    ServiceProvider.Settings.DefaultSession.AddFile(_otfile);
                }
            }
            else
            {
                MessageBox.Show("Ufraw not found !");
            }
        }
Exemplo n.º 3
0
        private void ShowUnhandeledException(DispatcherUnhandledExceptionEventArgs e)
        {
            e.Handled = true;

            Log.Error("Unhandled error ", e.Exception);
            ServiceProvider.Analytics.Error(e.Exception);
            string errorMessage =
                string.Format(
                    TranslationStrings.LabelUnHandledError,
                    e.Exception.Message + (e.Exception.InnerException != null
                                               ? "\n" +
                                           e.Exception.InnerException.Message
                                               : null));

            if (e.Exception.GetType() == typeof(MissingMethodException))
            {
                Log.Error("Damaged installation. Application exiting ");
                MessageBox.Show("Application crash !! Damaged installation!\nPlease unintall aplication from control panel and reinstall it!");
                Current?.Shutdown();
            }
            // check if wia 2.0 is registered
            // isn't a clean way
            if (errorMessage.Contains("{E1C5D730-7E97-4D8A-9E42-BBAE87C2059F}"))
            {
                MessageBox.Show(TranslationStrings.LabelWiaNotInstalled);
                PhotoUtils.RunAndWait("regwia.bat", "");
                MessageBox.Show(TranslationStrings.LabelRestartTheApplication);
                Application.Current.Shutdown();
            }
            else if (e.Exception.GetType() == typeof(OutOfMemoryException))
            {
                Log.Error("Out of memory. Application exiting ");
                MessageBox.Show(TranslationStrings.LabelOutOfMemory);
                if (Current != null)
                {
                    Current.Shutdown();
                }
            }
            else
            {
                if (MessageBox.Show(TranslationStrings.LabelAskSendLogFile, TranslationStrings.LabelApplicationError,
                                    MessageBoxButton.YesNo,
                                    MessageBoxImage.Error) == MessageBoxResult.Yes)
                {
                    var wnd = new ErrorReportWnd("Application crash " + e.Exception.Message, e.Exception.StackTrace);
                    wnd.ShowDialog();
                }
                if (
                    MessageBox.Show(errorMessage, TranslationStrings.LabelApplicationError, MessageBoxButton.YesNo,
                                    MessageBoxImage.Error) ==
                    MessageBoxResult.No)
                {
                    if (Current != null)
                    {
                        Current.Shutdown();
                    }
                }
            }
        }
Exemplo n.º 4
0
        private void ShowUnhandeledException(DispatcherUnhandledExceptionEventArgs e)
        {
            e.Handled = true;

            Log.Error("Unhandled error ", e.Exception);

            string errorMessage =
                string.Format(
                    TranslationStrings.LabelUnHandledError,

                    e.Exception.Message + (e.Exception.InnerException != null
                                   ? "\n" +
                                           e.Exception.InnerException.Message
                                   : null));

            // check if wia 2.0 is registered
            // isn't a clean way
            if (errorMessage.Contains("{E1C5D730-7E97-4D8A-9E42-BBAE87C2059F}"))
            {
                System.Windows.Forms.MessageBox.Show(TranslationStrings.LabelWiaNotInstalled);
                PhotoUtils.RunAndWait("regwia.bat", "");
                System.Windows.Forms.MessageBox.Show(TranslationStrings.LabelRestartTheApplication);
                Application.Current.Shutdown();
            }
            else if (e.Exception.GetType() == typeof(OutOfMemoryException))
            {
                Log.Error("Out of memory. Application exiting ");
                System.Windows.Forms.MessageBox.Show(TranslationStrings.LabelOutOfMemory);
                if (Current != null)
                {
                    Current.Shutdown();
                }
            }
            else
            {
                if (
                    MessageBox.Show(errorMessage, TranslationStrings.LabelApplicationError, MessageBoxButton.YesNo,
                                    MessageBoxImage.Error) ==
                    MessageBoxResult.No)
                {
                    if (Current != null)
                    {
                        Current.Shutdown();
                    }
                }
            }
        }
Exemplo n.º 5
0
        void Exec(double br)
        {
            string _infile      = ServiceProvider.Settings.SelectedBitmap.FileItem.FileName;
            string _otfile      = Path.Combine(Path.GetDirectoryName(_infile), Path.GetFileNameWithoutExtension(_infile) + (br > 0 ? "+" : "") + br + ".jpg");
            string _pathtoufraw =
                Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), "ufraw",
                             "ufraw-batch.exe");

            if (File.Exists(_pathtoufraw))
            {
                if (PhotoUtils.RunAndWait(_pathtoufraw,
                                          " --wb=camera --saturation=1.2 --exposure=" + br +
                                          " --black-point=auto --overwrite --out-type=jpg --output=" +
                                          _otfile + " " + _infile))
                {
                    ServiceProvider.Settings.DefaultSession.AddFile(_otfile);
                }
            }
            else
            {
                MessageBox.Show("Ufraw not found !");
            }
        }
Exemplo n.º 6
0
        public string Execute(FileItem fileItem, string infile, string dest, ValuePairEnumerator configData)
        {
            var  conf       = new ResizeTransformViewModel(configData);
            bool deleteFile = false;
            var  filename   = infile;

            if (fileItem.IsRaw)
            {
                string s = Path.Combine(Path.GetDirectoryName(fileItem.FileName),
                                        Path.GetFileNameWithoutExtension(fileItem.FileName) + ".jpg");
                if (File.Exists(s))
                {
                    filename = s;
                }
                else
                {
                    string dcraw_exe = Path.Combine(Settings.ApplicationFolder, "dcraw.exe");
                    if (File.Exists(dcraw_exe))
                    {
                        PhotoUtils.RunAndWait(dcraw_exe, string.Format(" -e {0}", fileItem.FileName));
                        string thumb = Path.Combine(Path.GetDirectoryName(fileItem.FileName),
                                                    Path.GetFileNameWithoutExtension(fileItem.FileName) + ".thumb.jpg");
                        if (File.Exists(thumb))
                        {
                            deleteFile = true;
                            filename   = thumb;
                        }
                    }
                }
                dest = Path.Combine(Path.GetDirectoryName(dest), Path.GetFileNameWithoutExtension(dest) + ".jpg");
            }
            using (MemoryStream fileStream = new MemoryStream(File.ReadAllBytes(filename)))
            {
                BitmapDecoder bmpDec = BitmapDecoder.Create(fileStream,
                                                            BitmapCreateOptions.PreservePixelFormat,
                                                            BitmapCacheOption.OnLoad);
                WriteableBitmap writeableBitmap;
                if (conf.KeepAspect)
                {
                    double dw = (double)conf.Width / bmpDec.Frames[0].PixelWidth;
                    writeableBitmap =
                        BitmapFactory.ConvertToPbgra32Format(BitmapLoader.GetBitmapFrame(bmpDec.Frames[0],
                                                                                         (int)(bmpDec.Frames[0].PixelWidth * dw),
                                                                                         (int)(bmpDec.Frames[0].PixelHeight * dw),
                                                                                         BitmapScalingMode.Linear));
                }
                else
                {
                    writeableBitmap =
                        BitmapFactory.ConvertToPbgra32Format(BitmapLoader.GetBitmapFrame(bmpDec.Frames[0], conf.Width, conf.Height, BitmapScalingMode.Linear));
                }

                BitmapLoader.Save2Jpg(writeableBitmap, dest);

                // remove temporally file created by dcraw
                if (deleteFile)
                {
                    File.Delete(filename);
                }
            }
            return(dest);
        }
Exemplo n.º 7
0
        public void CopyFiles(bool preview)
        {
            int counter = 0;

            try
            {
                _filenames.Clear();

                OnProgressChange("Copying files");
                WriteLog("Copying files");
                WriteShortLog("Copying files");

                foreach (FileItem fileItem in Files)
                {
                    string source = preview ? fileItem.LargeThumb : fileItem.FileName;

                    MagickImageInfo info = new MagickImageInfo();
                    info.Read(source);
                    string format = info.Format.ToString();

                    OnProgressChange(fileItem.Name + " format is:  " + format);
                    WriteLog(fileItem.Name + " format is:  " + format);
                    WriteShortLog(fileItem.Name + " format is:  " + format);


                    if (format == "Jpeg")
                    {
                        OnProgressChange("Copying file " + fileItem.Name);
                        WriteLog("Copying file " + fileItem.Name);
                        WriteShortLog("Copying file " + fileItem.Name);
                        string randomFile = Path.Combine(ProjetFolder, "image_" + counter.ToString("0000") + ".jpg");
                        AutoExportPluginHelper.ExecuteTransformPlugins(fileItem, PluginSetting.AutoExportPluginConfig, source, randomFile);
                        _filenames.Add(randomFile);
                        counter++;
                    }

                    if (format == "Tiff")
                    {
                        OnProgressChange("Converting file " + fileItem.Name);
                        WriteLog("Converting file " + fileItem.Name);
                        WriteShortLog("Converting file " + fileItem.Name);
                        string randomFile = Path.Combine(ProjetFolder, "image_" + counter.ToString("0000") + ".jpg");

                        try
                        {
                            using (MagickImage image = new MagickImage(source))
                            {
                                image.Format = MagickFormat.Jpeg;
                                image.Write(randomFile);
                            }
                            _filenames.Add(randomFile);
                            counter++;
                        }
                        catch (Exception exception)
                        {
                            Log.Error("Error converting Tiff file", exception);
                        }
                    }

                    if (format == "Nef" || format == "Cr2" || format == "Crw")
                    {
                        OnProgressChange("Converting file " + fileItem.Name);
                        WriteLog("Converting file " + fileItem.Name);
                        WriteShortLog("Converting file " + fileItem.Name);
                        string randomFile = Path.Combine(ProjetFolder, "image_" + counter.ToString("0000") + ".jpg");

                        try
                        {
                            string dcraw_exe = Path.Combine(Settings.ApplicationFolder, "dcraw.exe");
                            if (File.Exists(dcraw_exe))
                            {
                                PhotoUtils.RunAndWait(dcraw_exe,
                                                      string.Format(" -e -O \"{0}\" \"{1}\"", randomFile, source));
                                _filenames.Add(randomFile);
                                counter++;
                            }
                        }
                        catch (Exception exception)
                        {
                            Log.Error("Error converting Raw file", exception);
                        }
                    }

                    if (format != "Jpeg" && format != "Tiff" && format != "Nef" && format != "Cr2" && format != "Crw")
                    {
                        OnProgressChange(fileItem.Name + " has invalid format, will not be copied");
                        WriteLog(fileItem.Name + " has invalid format, will not be copied");
                        WriteShortLog(fileItem.Name + " has invalid format, will not be copied");
                    }


                    if (_shouldStop)
                    {
                        OnActionDone();
                        return;
                    }
                }
            }
            catch (Exception exception)
            {
                OnProgressChange("Error copy files " + exception.Message);
                WriteLog("Error copy files " + exception.Message);
                WriteShortLog("Error copy files " + exception.Message);
                Log.Error("Error copy files ", exception);
                _shouldStop = true;
            }
        }