From 8bf043b83471bd89f27968114bee37d42fac9e43 Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期二, 01 十二月 2020 17:27:11 +0800
Subject: [PATCH] 2020-12-1-3
---
HDL_ON/DAL/FileUtils.cs | 200 ++++++++++++++++++++++++++-----------------------
1 files changed, 107 insertions(+), 93 deletions(-)
diff --git a/HDL_ON/DAL/FileUtils.cs b/HDL_ON/DAL/FileUtils.cs
index fdc2ac8..3ca621b 100644
--- a/HDL_ON/DAL/FileUtils.cs
+++ b/HDL_ON/DAL/FileUtils.cs
@@ -2,7 +2,6 @@
using System.IO;
using System.Collections.Generic;
using Shared;
-using HDL_ON.DAL.Net;
namespace HDL_ON
{
@@ -408,107 +407,122 @@
}
/// <summary>
- /// 涓嬭浇鐢靛彴銆侀煶涔愩�丏LNA绛夌瓑缃戠粶鍥剧墖
+ ///
/// </summary>
/// <param name="fileName"></param>
- /// <param name="url"></param>
- public static void DownLoadImage(string fileName, string url)
+ /// <param name="imagePath"></param>
+ public static void FileCopyToRootPath(string oldPath, string fileName)
{
- #region 濡傛灉褰撳墠鐩綍涓嶅瓨鍦紝灏卞垵濮嬪寲
- string directioryPath = null;
- if (Shared.Application.IsPad)
+ System.IO.FileInfo fileInfo = new System.IO.FileInfo(oldPath);
+ if (fileInfo.Exists)
{
- directioryPath = "Pad/" + "MusicImage";
- }
- else
- {
- directioryPath = "Phone/" + "MusicImage";
- }
- directioryPath = Path.Combine(RootPath, directioryPath);
- if (!Directory.Exists(directioryPath))
- {
- Directory.CreateDirectory(directioryPath);
- }
- #endregion
-
- if (!File.Exists(fileName))
- {
- System.Threading.Tasks.Task.Run(() =>
- {
- FileStream fs = null;
- try
- {
- MyWebClient webClient = new MyWebClient();
- byte[] recevieBytes = webClient.DownloadData(new Uri(url));
- fs = new FileStream(fileName, FileMode.Create, FileAccess.Write);
- fs.Write(recevieBytes, 0, recevieBytes.Length);
- fs.Flush();
- }
- catch { }
- finally
- {
- if (fs != null)
- {
- fs.Close();
- }
- }
- });
+ fileInfo.CopyTo(Path.Combine(RootPath, fileName), true);
+ //Utlis.WriteLine("FileCopyToRootPath : " + Path.Combine(RootPath, fileName));
}
}
- /// <summary>
- /// 涓嬭浇鐢靛彴銆侀煶涔愩�丏LNA绛夌瓑缃戠粶鍥剧墖
- /// </summary>
- /// <param name="fileName"></param>
- /// <param name="url"></param>
- public static string DownLoadImageFormBaidu(string album, string artist)
- {
- var url = "http://tingapi.ting.baidu.com/v1/restserver/ting?from=qianqian&version=2.1.0&method=baidu.ting.search.catalogSug&format=json&query=" + artist;
- string directioryPath = "MusicImage";
- directioryPath = Path.Combine(RootPath, directioryPath);
- if (!Directory.Exists(directioryPath))
- {
- Directory.CreateDirectory(directioryPath);
- }
- try
- {
- var song = Newtonsoft.Json.JsonConvert.DeserializeObject<Song>(new HDL_ON.DAL.Net.MyWebClient().DownloadString(new Uri(url)));
- if (song == null)
- {
- return null;
- }
- foreach (var tempAlbum in song.album)
- {
- if (tempAlbum.albumname == album && artist == tempAlbum.artistname)
- {
- var bytes = new HDL_ON.DAL.Net.MyWebClient().DownloadData(new Uri(tempAlbum.artistpic.Split('@')[0] + "@s_1,w_160,h_160"));
- var filePath = Path.Combine(directioryPath, "AlbumArtistImage_" + album);
- var fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
- fs.Write(bytes, 0, bytes.Length);
- fs.Flush();
- fs.Close();
- return filePath;
- }
- }
+ ///// <summary>
+ ///// 涓嬭浇鐢靛彴銆侀煶涔愩�丏LNA绛夌瓑缃戠粶鍥剧墖
+ ///// </summary>
+ ///// <param name="fileName"></param>
+ ///// <param name="url"></param>
+ //public static void DownLoadImage(string fileName, string url)
+ //{
+ // #region 濡傛灉褰撳墠鐩綍涓嶅瓨鍦紝灏卞垵濮嬪寲
+ // string directioryPath = null;
+ // if (Shared.Application.IsPad)
+ // {
+ // directioryPath = "Pad/" + "MusicImage";
+ // }
+ // else
+ // {
+ // directioryPath = "Phone/" + "MusicImage";
+ // }
+ // directioryPath = Path.Combine(RootPath, directioryPath);
+ // if (!Directory.Exists(directioryPath))
+ // {
+ // Directory.CreateDirectory(directioryPath);
+ // }
+ // #endregion
- foreach (var tempArtist in song.artist)
- {
- if (artist == tempArtist.artistname)
- {
- var bytes = new HDL_ON.DAL.Net.MyWebClient().DownloadData(new Uri(tempArtist.artistpic.Split('@')[0] + "@s_1,w_160,h_160"));
- var filePath = Path.Combine(directioryPath, "AlbumArtistImage_" + artist);
- var fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
- fs.Write(bytes, 0, bytes.Length);
- fs.Flush();
- fs.Close();
- return filePath;
- }
- }
+ // if (!File.Exists(fileName))
+ // {
+ // System.Threading.Tasks.Task.Run(() =>
+ // {
+ // FileStream fs = null;
+ // try
+ // {
+ // MyWebClient webClient = new MyWebClient();
+ // byte[] recevieBytes = webClient.DownloadData(new Uri(url));
+ // fs = new FileStream(fileName, FileMode.Create, FileAccess.Write);
+ // fs.Write(recevieBytes, 0, recevieBytes.Length);
+ // fs.Flush();
+ // }
+ // catch { }
+ // finally
+ // {
+ // if (fs != null)
+ // {
+ // fs.Close();
+ // }
+ // }
+ // });
+ // }
+ //}
- }
- catch { }
- return null;
- }
+ ///// <summary>
+ ///// 涓嬭浇鐢靛彴銆侀煶涔愩�丏LNA绛夌瓑缃戠粶鍥剧墖
+ ///// </summary>
+ ///// <param name="fileName"></param>
+ ///// <param name="url"></param>
+ //public static string DownLoadImageFormBaidu(string album, string artist)
+ //{
+ // var url = "http://tingapi.ting.baidu.com/v1/restserver/ting?from=qianqian&version=2.1.0&method=baidu.ting.search.catalogSug&format=json&query=" + artist;
+ // string directioryPath = "MusicImage";
+ // directioryPath = Path.Combine(RootPath, directioryPath);
+ // if (!Directory.Exists(directioryPath))
+ // {
+ // Directory.CreateDirectory(directioryPath);
+ // }
+ // try
+ // {
+ // var song = Newtonsoft.Json.JsonConvert.DeserializeObject<Song>(new HDL_ON.DAL.Net.MyWebClient().DownloadString(new Uri(url)));
+ // if (song == null)
+ // {
+ // return null;
+ // }
+ // foreach (var tempAlbum in song.album)
+ // {
+ // if (tempAlbum.albumname == album && artist == tempAlbum.artistname)
+ // {
+ // var bytes = new HDL_ON.DAL.Net.MyWebClient().DownloadData(new Uri(tempAlbum.artistpic.Split('@')[0] + "@s_1,w_160,h_160"));
+ // var filePath = Path.Combine(directioryPath, "AlbumArtistImage_" + album);
+ // var fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
+ // fs.Write(bytes, 0, bytes.Length);
+ // fs.Flush();
+ // fs.Close();
+ // return filePath;
+ // }
+ // }
+
+ // foreach (var tempArtist in song.artist)
+ // {
+ // if (artist == tempArtist.artistname)
+ // {
+ // var bytes = new HDL_ON.DAL.Net.MyWebClient().DownloadData(new Uri(tempArtist.artistpic.Split('@')[0] + "@s_1,w_160,h_160"));
+ // var filePath = Path.Combine(directioryPath, "AlbumArtistImage_" + artist);
+ // var fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
+ // fs.Write(bytes, 0, bytes.Length);
+ // fs.Flush();
+ // fs.Close();
+ // return filePath;
+ // }
+ // }
+
+ // }
+ // catch { }
+ // return null;
+ //}
}
[System.Serializable]
--
Gitblit v1.8.0