示例#1
0
        /// <summary>
        /// Read func for the CWLU-format<para />
        /// Name: CWishlistUncde (UTF16/Unicode and no longer useless UTF32 in Base64)<para />
        /// File version: 3 (saved, checked)<para />
        /// Format versions: 1 (saved, checked)
        /// </summary>
        static WL cwlu_load(string file)
        {
            dbg("[CWLU]Reading file...");
            ZipArchive zip = ZipFile.Open(file, ZipArchiveMode.Read, ASCII);

            if (zip.read_entry_byte("F") != 3 || zip.read_entry_byte("V") != 1)
            {
                throw new Exception("Invalid CWLU file.");
            }
            XmlReader xml = XmlReader.Create(new StreamReader(zip.GetEntry("W").Open(), Unicode));

            dbg("[CWLU]Initialized ZIP and XML.");
            List <Item> items = new List <Item>();

            while (xml.Read())
            {
                if (xml.Name == "i")
                {
                    Item i = new Item(xml.GetAttribute("n"), xml.GetAttribute("u"));
                    items.Add(i);
                    dbg($"[CWLU]Read {i.dbgfmt()}");
                }
            }
            xml.Close();
            zip.Dispose();
            WL wl = new WL(items);

            dbg("[CWLU]Finished.");
            return(wl);
        }
示例#2
0
 /// <summary>
 /// Loads the WL from the given file to loaded_wl, wl and current_file.
 /// </summary>
 /// <param name="file">The file to load the CWL from.</param>
 public void load_wl(string file)
 {
     lock (blist_mutex)
     {
         wl           = load(file);
         current_file = file;
         loaded_wl    = new Item[wl];
         farrcpyitm(wl, loaded_wl);
     }
     try_update_ui();
 }
示例#3
0
        /// <summary>
        /// Save func for the CWLD-format<para />
        /// For information on the format check the load/read func
        /// </summary>
        public static void cwld_save(WL wl, string file)
        {
            dbg("[CWLD]Saving file...");
            Stream s = File.Open(file, Create, FileAccess.Write);

            s.write(cwld_header);
            s.write(4, 3);
            dbg("[CWLD]Wrote header...");
            DeflateStream d = new DeflateStream(s, CompressionLevel.Optimal, false);

            foreach (Item i in wl)
            {
                i.write_bytes(d, 3);
                dbg("[CWLD]Wrote {0}...", i.dbgfmt());
            }
            d.Close();
            dbg("[CWLD]Saved file.");
        }
示例#4
0
 void new_click(object _, EventArgs e)
 {
     if ((wl > 0 && current_file == "") || (current_file != "" && !arrequ(wl.items, loaded_wl)) &&
         MessageBox.Show(get_translated("new"), "", YesNo) == No)
     {
         return;
     }
     lock (blist_mutex)
     {
         if (current_file != "")
         {
             add_current_file_to_recent_items();
             current_file = "";
         }
         wl        = NEW;
         loaded_wl = EMPTY;
     }
     try_update_ui();
 }
示例#5
0
        public void init()
        {
            dbg("[Form1.init()]Form1 initializing...");

            if (args.Length > 0)
            {
                load_wl(args[0]);
            }
            else
            {
                lock (blist_mutex) wl = NEW;
            }

            int appdir_create_pid = start(() =>
                                          { if (!Directory.Exists(appdir))
                                            {
                                                Directory.CreateDirectory(appdir);
                                            }
                                          });

            int langdir_create_pid = start(() =>
                                           { if (!Directory.Exists(lang_dir))
                                             {
                                                 Directory.CreateDirectory(lang_dir);
                                             }
                                           });

            int save_langs_if_not_exist_pid = start(() =>
            {
                join(langdir_create_pid);
                if (!File.Exists(lang_de))
                {
                    File.WriteAllText(lang_de, de_lang_xml);
                }
                if (!File.Exists(lang_en))
                {
                    File.WriteAllText(lang_en, en_lang_xml);
                }
            });

            start(() =>
            {
                join(appdir_create_pid);
                lock (recents_mutex)
                    if (File.Exists(recents_file))
                    {
                        try
                        {
                            recents = load_recents(recents_file);
                            dbg("[Form1-InitThread]Read {0} recent files.", recents.Count);
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show("Corrupted recents:\n\n" + e);
                            try
                            {
                                write_recents(recents_file, recents);
                            }
                            catch (Exception e1)
                            {
                                MessageBox.Show("Unable to write new recents:\n\n" + e1);
                                try { File.Delete(recents_file); }
                                catch (Exception e2)
                                {
                                    MessageBox.Show("Can't even delete the old recents:\n\n" + e2,
                                                    "I guess you really blew up your PC...");
                                }
                            }
                        }
                    }
                    else
                    {
                        write_recents(recents_file, recents);
                    }
            });

            start(() =>
            {
                join(save_langs_if_not_exist_pid);

                load_langs(lang_dir);

                bool reload_langs = false;

                if (get_lang("de").version < ver_int)
                {
                    File.WriteAllText(lang_de, de_lang_xml);
                    reload_langs = true;
                }

                if (get_lang("en").version < ver_int)
                {
                    File.WriteAllText(lang_en, en_lang_xml);
                    reload_langs = true;
                }

                if (reload_langs)
                {
                    clear_langs();
                    load_langs(lang_dir);
                }

                if (File.Exists(lang_file))
                {
                    select_lang(File.ReadAllText(lang_file, Encoding.ASCII));
                }
                else if (File.Exists(legacy_lang_file))
                {
                    byte[] c = File.ReadAllBytes(legacy_lang_file);
                    if (c.Length == 1)
                    {
                        select_lang(c[0] == 0 ? "en" : "de");
                    }
                    else
                    {
                        select_lang(ascii(c));
                    }
                }

                if (!File.Exists(restore_backup))
                {
                    File.WriteAllBytes(restore_backup, new byte[] { 0 });
                }
                else if (File.ReadAllBytes(restore_backup)[0] != 0 &&
                         GetProcessesByName("CWishlist_win").Length < 2 &&
                         MessageBox.Show(get_translated("restore_backup"),
                                         "",
                                         YesNo) == Yes)
                {
                    lock (backup_mutex) wl = cwld_load(backup_file);
                }
            });

            load_width();
            load_height();
            load_color();

            thread_manager.finishall();
            update_ui();
            label3.Visible = false;

            dbg("[Form1.init()]Form1 initialized.");
        }
示例#6
0
 public bool Equals(WL wl) => wl == this;