Esempio n. 1
0
        /*-------------------------------------------------------------------------
         * 更新確認
         * ---------------------------------------------------------------------------*/
        private void button4_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            // バージョンを確認する
            downloadfile dlf    = new downloadfile();
            bool         result = dlf.Download(def.VERSION_URL, def.VERSION_FNAME);

            Cursor = Cursors.Default;

            if (!result)
            {
                // 更新しない
                MessageBox.Show(this, "更新情報が取得できませんでした。\nインターネットの接続を確認してください。", "更新確認エラー", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            dlf = null;

            // 更新されたデータがあるかどうか確認する
            string        line    = "";
            List <string> data    = new List <string>();
            int           version = 0;

            try{
                using (StreamReader sr = new StreamReader(
                           def.VERSION_FNAME, Encoding.GetEncoding("Shift_JIS"))){
                    // バージョン
                    line    = sr.ReadLine();
                    version = Convert.ToInt32(line);

                    // 残り
                    while ((line = sr.ReadLine()) != null)
                    {
                        data.Add(line);
                    }
                }
            }catch {
                MessageBox.Show(this, "バージョン情報が確認できません。\n更新確認に失敗しました。", "更新確認エラー", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (version > def.VERSION)
            {
                // 更新されている
                check_update_result dlg = new check_update_result(data.ToArray());
                dlg.ShowDialog(this);
                dlg.Dispose();
            }
            else
            {
                // 更新されていない
                MessageBox.Show(this, "更新されたソフトウェアは見つかりませんでした。\nお使いのバージョンが最新です。", "更新確認結果", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Esempio n. 2
0
        private bool validatefile(downloadfile file)
        {
            bool   isvalid  = false;
            string filename = localfolder + "\\" + file.dir + "\\" + file.filetempname;

            // MessageBox.Show(file.filemd5 + "////" + createmd5(filename));
            if (File.Exists(filename) && (createmd5(filename) == file.filemd5))
            {
                isvalid = true;
            }
            return(isvalid);
        }
Esempio n. 3
0
        private void renamefile(downloadfile file)
        {
            var  filepath = localfolder + "\\" + file.dir + "\\" + file.filetempname;
            long length   = new System.IO.FileInfo(filepath).Length;

            if (File.Exists(filepath) & length > 0)
            {
                try

                {
                    File.Move(localfolder + "\\" + file.dir + "\\" + file.filetempname, localfolder + "\\" + file.dir + "\\" + file.filename);
                }
                catch (Exception ex)
                {
                    Reset_On_Error(ex);
                }
            }
        }
Esempio n. 4
0
        string[] testsave()
        {
            downloadfile test = new downloadfile();

            string[] urlmass, p = new string[0];
            for (int i = 1; i < dataGridView1.RowCount; i++)
            {
                urlmass = Convert.ToString(dataGridView1[25, i].Value).Split(',');
                for (int j = 0; j < urlmass.Length; j++)
                {
                    if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + @"\img\" + Path.GetFileName(urlmass[j])))
                    {
                        test.savefile(urlmass[j], AppDomain.CurrentDomain.BaseDirectory + @"\img\");
                    }
                    Array.Resize(ref p, p.Length + 1);
                    p[p.Length - 1] = Path.GetFileName(urlmass[j]);
                }
            }

            return(p);
        }
Esempio n. 5
0
        private void createdownloadqueue()
        {
            // stop timer so it can not intrupt on going process
            dispatcherTimer.Stop();
            // get local file dictionary.
            showNotificationMessage("Dowloading File list", 0);
            LIVEFILES = GetlivefilesData(); // get live files

            try
            {
                List <myfile> currentfiles = new List <myfile>();

                List <String> fileEntries = DirSearch(localfolder);

                LOCALFILES = new Dictionary <string, myfile>();

                foreach (string fileName in fileEntries)
                {
                    FileInfo fi = new FileInfo(fileName);

                    if (fi.Extension != ".part")
                    {
                        myfile mf = new myfile();
                        mf.name = fi.Name;
                        mf.size = fi.Length;

                        mf.dir = System.IO.Path.GetDirectoryName(fileName);

                        mf.md5 = createmd5(fileName).ToLower();


                        if (!LOCALFILES.ContainsKey(mf.md5))
                        {
                            LOCALFILES.Add(mf.md5, mf);
                        }
                    }
                    else if (fi.Extension == ".part")
                    {
                        DOWNLOADPENDING.Add(System.IO.Path.GetFileNameWithoutExtension(fi.Name));
                    }
                }


                // get live file dictionary.



                // check both dictionary and manage downloadqueue.

                foreach (String k in LOCALFILES.Keys.ToList())
                {
                    var i = LIVEFILES.ContainsKey(k.Trim());

                    if (!i)
                    {
                        var localitem = LOCALFILES[k];


                        if (File.Exists(localitem.dir + "\\" + localitem.name))
                        {
                            File.Delete(localitem.dir + "\\" + localitem.name);
                            bool isEmpty = !Directory.EnumerateFiles(localitem.dir).Any();
                            if (isEmpty)
                            {
                                Directory.Delete(localitem.dir, true);
                            }
                            showNotificationMessage(localitem.dir + "\\" + localitem.name + "removing... ", 0);
                        }
                        //  LOCALFILES.Remove(k.Trim());
                        //  LOCALFILES.Clear();
                    }
                }

                // cross checking of existing file to live files.
                while (DOWNLOADPENDING.Count > 0)
                {
                    showNotificationMessage("Genarating Pending Download List", 0);
                    String k = DOWNLOADPENDING.First();
                    var    i = LIVEFILES.ContainsKey(k);
                    if (i)
                    {
                        var          item = LIVEFILES[k];
                        downloadfile df   = new downloadfile(item.name, item.md5 + ".part", item.md5, item.size, 0, item.dir);

                        myfile mf = new myfile();
                        mf.name = item.name;
                        mf.size = item.size;
                        mf.md5  = item.md5;
                        if (!LOCALFILES.ContainsKey(mf.md5))
                        {
                            LOCALFILES.Add(mf.md5, mf);
                        }
                        // LOCALFILES.Add(mf.md5, mf);

                        DOWNLOADQUEUE.Add(df);
                    }
                    else
                    {
                        //TODO:delete the unwanted .partfiles

                        var localFileList = DirSearch(localfolder);
                        var match         = localFileList.FirstOrDefault(stringToCheck => stringToCheck.Contains(k));

                        if (File.Exists(match))
                        {
                            File.Delete(match);
                        }
                        // deletefile(k + ".part");
                    }
                    DOWNLOADPENDING.Remove(k);
                }

                // checking for new file
                foreach (String lv in LIVEFILES.Keys)
                {
                    var i = LOCALFILES.ContainsKey(lv);
                    if (!i)
                    {
                        var item = LIVEFILES[lv];


                        if (!File.Exists(localfolder + "\\" + item.dir + "\\" + item.md5 + ".part"))
                        {
                            Directory.CreateDirectory(System.IO.Path.GetDirectoryName(localfolder + "\\" + item.dir + "\\" + item.md5 + ".part"));

                            File.Create(localfolder + "\\" + item.dir + "\\" + item.md5 + ".part").Close();
                        }
                        downloadfile df = new downloadfile(item.name, item.md5 + ".part", item.md5, item.size, 0, item.dir);
                        //  MessageBox.Show("new" + item.name + item.md5 + ".part"  + item.dir);
                        DOWNLOADQUEUE.Add(df);
                    }
                }

                dispatcherTimer.Start();
            }
            catch (Exception ex)
            {
                Reset_On_Error(ex);
            }
        }
Esempio n. 6
0
        void createstructimg(bool create_minature)
        {
            img = new image[0];
            int index = 0;

            string[] urlmass;
            string   path      = AppDomain.CurrentDomain.BaseDirectory + "p";
            string   path_temp = AppDomain.CurrentDomain.BaseDirectory + "img";
            //MessageBox.Show(path);
            DirectoryInfo di;
            downloadfile  download = new downloadfile();

            init_img_type();
            string[] file_name = testsave();

            int file_name_k = 0;

            try
            {
                if (!Directory.Exists(path))
                {
                    di = Directory.CreateDirectory(path);
                }

                for (int i = 1; i < dataGridView1.RowCount; i++)
                {
                    urlmass = Convert.ToString(dataGridView1[25, i].Value).Split(',');
                    for (int j = 0; j < urlmass.Length; j++)
                    {
                        Array.Resize(ref img, img.Length + 1);
                        img[img.Length - 1]            = new image();
                        img[img.Length - 1].id_image   = index;
                        img[img.Length - 1].id_product = Convert.ToInt32(dataGridView1[0, i].Value);
                        img[img.Length - 1].legend     = Convert.ToString(dataGridView1[2, i].Value);
                        img[img.Length - 1].patch      = path + createpatchimg(index);
                        img[img.Length - 1].position   = j;
                        index++;
                        if (create_minature)
                        {
                            if (!Directory.Exists(img[img.Length - 1].patch))
                            {
                                di = Directory.CreateDirectory(img[img.Length - 1].patch);
                            }
                            if (!File.Exists(img[img.Length - 1].patch + @"\" + img[img.Length - 1].id_image + ".jpg"))
                            {
                                ResizeImage(path_temp + "\\" + file_name[file_name_k], img[img.Length - 1].patch + @"\" + img[img.Length - 1].id_image + ".jpg", 600, 600, true);
                            }
                            for (int type_i = 0; type_i < type.Length; type_i++)
                            {
                                if (!File.Exists(img[img.Length - 1].patch + @"\" + type[type_i].name + ".jpg"))
                                {
                                    ResizeImage(path_temp + "\\" + file_name[file_name_k], img[img.Length - 1].patch + @"\" + img[img.Length - 1].id_image + "-" + type[type_i].name + ".jpg", type[type_i].width, type[type_i].height, true);
                                }
                            }
                            file_name_k++;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Ошибка создания струтуры папок. Не были созданы или были созданы частично: " + e.ToString(), "Оповещение", MessageBoxButtons.OK);
            }
            finally { }
        }