Пример #1
0
        public MainWindow()
            : base(Gtk.WindowType.Toplevel)
        {
            Build ();

            if (Directory.Exists(Configuration.DesignFormatsPath))
            {
                string[] files = Directory.GetFiles(Configuration.DesignFormatsPath, "*.dll");
                foreach(string f in files)
                {
                    Assembly a = Assembly.LoadFile(f);
                    Type[] types = a.GetTypes();
                    foreach(Type t in types)
                    {
                        if(t.GetInterface("IDesignFormat") != null)
                        {
                            object[] customAttributes = t.GetCustomAttributes(typeof(DesignFormatAttribute), false);
                            if(customAttributes.Length == 1)
                            {
                                DesignFormatAttribute dfa = (DesignFormatAttribute)customAttributes[0];
                                log.InfoFormat("Loaded design format {0}", dfa.Name);

                                DesignFormat df = new DesignFormat(
                                                                   dfa.Name,
                                                                   dfa.Description,
                                                                   dfa.FileExtensions,
                                                                   dfa.fileHeader,
                                                                   (IDesignFormat)Activator.CreateInstance(t));

                                FileManager.AvailableFormats.Add(df);
                            }
                        }
                    }
                }
            }

            pesView.DoubleBuffered = true;
            pesView.AppendColumn("Display", new Gtk.CellRendererPixbuf(), "pixbuf" , 0);
            pesView.AppendColumn("Name", new Gtk.CellRendererText(), "text", 1);
            pesView.ShowAll();
            pesView.HeadersVisible = true;
            pesView.BorderWidth = 2;
            pesView.EnableGridLines = TreeViewGridLines.Horizontal;
            pesStore = new Gtk.NodeStore(typeof(PesFile));

            index = FileManager.OpenIndexFile(Configuration.IndexFilePath);

            FileManager.RefreshIndexFile(ref index);

            loadDisplay();
        }
Пример #2
0
        public static void UpdateIndexFile(string[] paths, ref IndexFile index)
        {
            if (paths == null) throw new ArgumentNullException("paths");
            if (index == null) throw new ArgumentNullException("index");

            log.Info("Refreshing index file.");
            Hashtable fileLib = RefreshIndexFile(ref index);

            foreach (string path in paths)
            {
                if (Directory.Exists(path))
                {
                    log.DebugFormat("Scanning: {0}", path);
                    string[] files = Directory.GetFiles(path, "*", SearchOption.AllDirectories);
                    foreach (string file in files)
                    {
                        bool isDupe = false;
                        FileInfo fi = new FileInfo(file);

                        foreach (DesignFormat df in FileManager.AvailableFormats)
                        {
                            if (df.Equals(fi.FullName))
                            {
                                log.DebugFormat("The file {0} is a {1}", file, df.Name);

                                log.DebugFormat("Hashing file: {0}", file);
                                string hash = md5(file);
                                log.Debug(hash);

                                DataFile newFile = null;

                                if (fileLib.ContainsKey(hash))
                                {
                                    isDupe = true;
                                    newFile = (DataFile)fileLib[hash];

                                    log.DebugFormat("The hash is already in the index for: {0}", newFile.FilePath);
                                    if (newFile.FilePath != fi.FullName)
                                    {
                                        bool exists = false;
                                        foreach (DuplicateFile dupe in newFile.DuplicateFiles)
                                        {
                                            if (fi.FullName == dupe.FilePath)
                                            {
                                                exists = true;
                                                break;
                                            }
                                        }
                                        if (!exists) newFile.DuplicateFiles.Add(new DuplicateFile(fi.Name, fi.FullName));
                                    }
                                }
                                else
                                {
                                    log.DebugFormat("Adding new file {0}.", fi.Name);
                                    newFile = new DataFile(fi.Name, fi.FullName);
                                    newFile.FileHash = hash;
                                    newFile.Status = FileStatus.InLibrary;
                                    newFile.SvgPath = createSvg(df.Format, fi.FullName);
                                    newFile.IconPath = createIcon(newFile.SvgPath);
                                    index.DataFiles.Add(newFile);
                                    fileLib.Add(hash, newFile);
                                }
                            }
                            df.Format.CloseFile();
                        }
                    }
                }
            }
            SaveIndexFile(index, Embroidr.UI.Configuration.IndexFilePath);
        }
Пример #3
0
 /// <summary>
 /// Serializes an <see cref="IndexFile"/> object to an xml file.
 /// </summary>
 /// <param name="index">
 /// A <see cref="IndexFile"/> containing the data to serialize.
 /// </param>
 /// <param name="path">
 /// A <see cref="System.String"/> representing an xml file path that will contain the serialized data.
 /// </param>
 public static void SaveIndexFile(IndexFile index, string path)
 {
     log.InfoFormat("Saving index file to path: {0}", path);
     if (index == null) throw new ArgumentNullException("index");
     if (File.Exists(path))
     {
         Stream s = null;
         try
         {
             s = new FileStream(path, FileMode.Truncate);
             SaveIndexFile(index, s);
             return;
         }
         catch (Exception ex)
         {
             log.Fatal("An exception was thrown while serializing the index file.");
             log.Fatal(ex.Message);
             log.Fatal(ex.StackTrace);
             throw ex;
         }
         finally
         {
             if (s != null) s.Dispose();
         }
     }
     log.Fatal("Could not open the index file. File does not exist.");
     throw new FileNotFoundException("Could not open file path. File does not exist.", path);
 }
Пример #4
0
        /// <summary>
        /// Serializes an <see cref="IndexFile"/> object to an xml file.
        /// </summary>
        /// <param name="index">
        /// A <see cref="IndexFile"/> containing the data to serialize.
        /// </param>
        /// <param name="s">
        /// A <see cref="Stream"/> to which the serialized data will be written.
        /// </param>
        public static void SaveIndexFile(IndexFile index, Stream s)
        {
            log.Info("Saving index file to stream.");
            if (index == null) throw new ArgumentException("index");
            if (s == null) throw new ArgumentNullException("s");

            if (s.CanWrite)
            {
                XmlSerializer xsr = null;
                XmlTextWriter xtw = null;
                try
                {
                    xsr = new XmlSerializer(typeof(IndexFile));
                    xtw = new XmlTextWriter(s, System.Text.Encoding.Default);
                    if (Embroidr.UI.Configuration.FormatXmlOutput)
                    {
                        xtw.Formatting = Formatting.Indented;
                        xtw.Indentation = 1;
                        xtw.IndentChar = '\t';
                    }
                    xsr.Serialize(xtw, index);
                    return;
                }
                catch (Exception ex)
                {
                    log.Fatal("An exception was thrown while serializing the index file.");
                    log.Fatal(ex.Message);
                    log.Fatal(ex.StackTrace);
                    throw ex;
                }
                finally
                {
                    log.Info("Closing the XmlTextWriter.");
                    if (xtw != null) xtw.Close();
                }
            }
            log.Fatal("Could not write to the index file stream.");
            throw new IOException("The index file stream could not be written to.");
        }
Пример #5
0
        public static Hashtable RefreshIndexFile(ref IndexFile index)
        {
            if (index == null) throw new ArgumentNullException("index");

            Hashtable fileLib = new Hashtable();
            log.Info("Removing deleted files from the index.");
            foreach (DataFile f in index.DataFiles)
            {
                if (!fileLib.ContainsKey(f.FileHash)) fileLib.Add(f.FileHash, f);
                if (!File.Exists(f.FilePath) && f.Status != FileStatus.Deleted)
                {
                    log.DebugFormat("Marking file as deleted in the index: {0}", f.FilePath);
                    f.Status = FileStatus.Deleted;
                }
                else
                {
                    if (f.SvgPath == null || (f.SvgPath != null && !File.Exists(f.SvgPath)))
                        f.SvgPath = createSvg(f.FilePath);

                    if (f.IconPath == null || (f.IconPath != null && !File.Exists(f.IconPath)))
                        f.IconPath = createIcon(f.SvgPath);
                }
            }
            return fileLib;
        }