Example #1
0
        public static bool DownloadFile(string uri, string localfile)
        {
            try
            {
                HttpWebRequest request = WebRequest.Create(uri) as HttpWebRequest;
                SetRequestHeaders(request);
                HttpWebResponse response   = request.GetResponse() as HttpWebResponse;
                Stream          dataStream = response.GetResponseStream();
                //File.Delete(localfile);
                TDCGExplorer.FileDelete(localfile);
                Stream fileStream = File.Create(localfile);

                BufferedStream bufferedDataStream = new BufferedStream(dataStream);
                BufferedStream bufferedFileStream = new BufferedStream(fileStream);

                byte[] buf = new byte[1024];
                int    len;
                while ((len = bufferedDataStream.Read(buf, 0, buf.Length)) > 0)
                {
                    bufferedFileStream.Write(buf, 0, len);
                }

                bufferedFileStream.Flush();
                bufferedFileStream.Close();
                bufferedDataStream.Close();
                response.Close();

                return(true);
            }
            catch (Exception e)
            {
                TDCGExplorer.SetToolTips("Error DownloadFile : " + e.Message);
            }
            return(false);
        }
Example #2
0
        public static void OpenTahEditor(GenericTahInfo entry)
        {
#if false
            string tahdbpath = GetTahDbPath(entry);
            // 同じDBエントリを開いているエディタタブが存在しないかチェックする。
            foreach (TabPage tabpage in TDCGExplorer.MainFormWindow.TabControlMainView.Controls)
            {
                TAHEditor edit = tabpage.Controls[0] as TAHEditor;
                if (edit != null)
                {
                    if (edit.TahDBPath == tahdbpath)
                    {
                        MessageBox.Show("既にこのTAHを開いています。", "エラー", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                }
            }
            // 既にファイルが存在しないかチェックする.
            if (File.Exists(tahdbpath))
            {
                string path;
                using (TAHLocalDB tahdb = new TAHLocalDB())
                {
                    tahdb.Open(tahdbpath);
                    path = tahdb["source"];
                }
                if (path != entry.path)
                {
                    if (MessageBox.Show("別のTAHファイルを格納しているDBがあります。\n削除して新規作成しますか?", "DBの更新", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
                    {
                        // ファイルを削除する.
                        //File.Delete(tahdbpath);
                        TDCGExplorer.FileDelete(tahdbpath);
                        // 新規作成する.
                        TAHEditor editor = null;
                        try
                        {
                            editor = new TAHEditor(tahdbpath, new GenericZipsTahInfo(entry));
                            TDCGExplorer.MainFormWindow.AssignTagPageControl(editor);
                            editor.SelectAll();
                        }
                        catch (Exception)
                        {
                            if (editor != null)
                            {
                                editor.Dispose();
                            }
                        }
                    }
                }
                else
                {
                    // 既にあるファイルをオープンする.
                    TAHEditor editor = null;
                    try
                    {
                        editor = new TAHEditor(tahdbpath, null);
                        TDCGExplorer.MainFormWindow.AssignTagPageControl(editor);
                        editor.SelectAll();
                    }
                    catch (Exception)
                    {
                        if (editor != null)
                        {
                            editor.Dispose();
                        }
                    }
                }
            }
            else
            {
                // 新規に作成する.
                TAHEditor editor = null;
                try
                {
                    editor = new TAHEditor(tahdbpath, new GenericZipsTahInfo(entry));
                    TDCGExplorer.MainFormWindow.AssignTagPageControl(editor);
                    editor.SelectAll();
                }
                catch (Exception)
                {
                    if (editor != null)
                    {
                        editor.Dispose();
                    }
                }
            }
#else
            // 新規に作成する.
            TAHEditor editor = null;
            try
            {
                editor = new TAHEditor(new GenericZipsTahInfo(entry));
                TDCGExplorer.MainFormWindow.AssignTagPageControl(editor);
                editor.SelectAll();
            }
            catch (Exception)
            {
                if (editor != null)
                {
                    editor.Dispose();
                }
            }
#endif
        }
Example #3
0
 public static void DeleteTahEditorFile(GenericTahInfo entry)
 {
     //File.Delete(GetTahDbPath(entry));
     TDCGExplorer.FileDelete(GetTahDbPath(entry));
 }