/// <summary> /// add information to upload a file, also perform check of file size and file existing /// </summary> private bool AddFormFile(LibCurl.MultiPartForm mf, string fileName, string field) { if (fileName != "") { if (!DrutNETBase.FileExists(fileName)) { sendLogEvent("Can't find file : " + fileName + "\n", "Curl", Enums.MessageType.Error); return(false); } else if ((new FileInfo(fileName).Length / 1024) > Enums.MAXFILESIZEKB) { sendLogEvent(fileName + " size is bigger than limit (" + (Enums.MAXFILESIZEKB / 1024).ToString() + "MB)" + "\n", "Curl", Enums.MessageType.Error); return(false); } else { LibCurl.CURLFORMcode res = mf.AddSection(LibCurl.CURLformoption.CURLFORM_COPYNAME, field, LibCurl.CURLformoption.CURLFORM_FILE, fileName, LibCurl.CURLformoption.CURLFORM_END); if (res != LibCurl.CURLFORMcode.CURL_FORMADD_OK) { sendLogEvent("Can't add Curl file: " + res.ToString() + "\n", "Curl", Enums.MessageType.Error); return(false); } else { return(true); } } } return(false); }
static public void WriteAutoCompleteFile(string autoCompleteStr, string path) { DrutNETBase.CreateDir(DrutNETBase.GetPath(path));//create directory if not existing TextWriter autoCompleteFile = new StreamWriter(path, true); autoCompleteFile.WriteLine(autoCompleteStr); autoCompleteFile.Close(); }
public static void UnZip(string pathToUnZip, string targetFolder) { FastZip fz = new FastZip(); try { fz.ExtractZip(pathToUnZip, targetFolder, ""); } catch (Exception e) { DrutNETBase.sendLogEvent("Unzip Error : " + e.Message, "ZIP", Enums.MessageType.Error); } }
static public string[] ReadAutoCompleteFile(string path) { List <string> valList = new List <string>(); if (DrutNETBase.FileExists(path)) { TextReader autoCompleteFile = new StreamReader(path); string val; while ((val = autoCompleteFile.ReadLine()) != null) { valList.Add(val); } autoCompleteFile.Close(); } return(valList.ToArray()); }
/// <summary> /// return a unique dir name /// </summary> /// <param name="dir">Directory without ending slash </param> public static string GetUniqueDirectory(string dir, bool useUnderScore) { //rename file if it exists int i = 0; string org = dir; while (DrutNETBase.DirectoryExists(dir)) { string separator = "-"; if (useUnderScore) { separator = "_"; } dir = org + separator + i.ToString(); i++; } return(dir); }
public bool DownloadFile(string httpPath, string savePath) { try { if (_isloggedIn) { easy.SetOpt(LibCurl.CURLoption.CURLOPT_WRITEFUNCTION, wf); fileDownload = new FileStream(savePath, FileMode.Create); ///replace space with %20 string a = " "; string b = "&20"; httpPath = httpPath.Replace(a, b); easy.SetOpt(LibCurl.CURLoption.CURLOPT_URL, httpPath); LibCurl.CURLcode exec = easy.Perform(); //CURLcode exec = DrupCurlPerform(); double d = 0; easy.GetInfo(LibCurl.CURLINFO.CURLINFO_CONTENT_LENGTH_DOWNLOAD, ref d); //easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION,null); fileDownload.Close(); if ((d == 0) || (this.HttpConnectCode != 200) || (!DrutNETBase.FileExists(savePath))) { sendLogEvent("Can't download file with Curl: " + exec.ToString() + "\n", "Curl", Enums.MessageType.Error); return(false); } return(true); } else { sendLogEvent("CURL not logged-in", "Curl" + "\n", Enums.MessageType.Error); return(false); } } catch (Exception ex) { errorMessage(ex.Message); return(false); } }
public static string GetUniqueFileName(string sourceFN, bool useUnderScore) { //rename file if it exists int i = 0; string org = sourceFN; while (DrutNETBase.FileExists(sourceFN)) { string separator = "-"; if (useUnderScore) { separator = "_"; } sourceFN = System.IO.Path.GetDirectoryName(org) + "\\" + System.IO.Path.GetFileNameWithoutExtension(org) + separator + i.ToString() + System.IO.Path.GetExtension(org); i++; } return(sourceFN); }