Cross platform issue

Feb 20, 2009 at 7:38 AM
Due to different pathname separator, HD-Trailers.NET Downloader cannot saving files properly in unix systems.
I made a path to solve this problem, tested on my FreeBSD-7.1 with mono-2.0.1.

Here is the patch:
--- Program.cs.orig 2009-02-20 15:25:18.000000000 +0800
+++ Program.cs 2009-02-20 15:24:37.000000000 +0800
@@ -30,7 +30,7 @@ namespace HDTrailersNETDownloader
         static int KeepFor;
         static FileStream logFS;
         static StreamWriter sw;
-
+        static string pathsep = Path.DirectorySeparatorChar.ToString();
         #endregion
 
         static void Main(string[] args)
@@ -90,13 +90,13 @@ namespace HDTrailersNETDownloader
                         {
                             bool tempDirectoryCreated = false;
 
-                            if (!Directory.Exists(DownloadFolder + @"\" + feedItems[i].Title.Replace(":", "")))
+                            if (!Directory.Exists(DownloadFolder + pathsep + feedItems[i].Title.Replace(":", "")))
                             {
                                 tempDirectoryCreated = true;
-                                Directory.CreateDirectory(DownloadFolder + @"\" + feedItems[i].Title.Replace(":", ""));
+                                Directory.CreateDirectory(DownloadFolder + pathsep + feedItems[i].Title.Replace(":", ""));
                             }
 
-                            tempBool = GetTrailer(tempTrailerURL, feedItems[i].Title, DownloadFolder + @"\" + feedItems[i].Title.Replace(":", "") + @"\");
+                            tempBool = GetTrailer(tempTrailerURL, feedItems[i].Title, DownloadFolder + pathsep + feedItems[i].Title.Replace(":", "") + pathsep);
 
                             //If download went ok, and we're using exclusions, add to list
                             if (tempBool && UseExclusions)
@@ -108,21 +108,21 @@ namespace HDTrailersNETDownloader
 
                             //Assuming we downloaded the trailer OK and the config has been set to grab posters...
                             if (tempBool && GrabPoster)
-                                GetPoster(CurrentSource, DownloadFolder + @"\" + feedItems[i].Title.Replace(":", "") + @"\");
+                                GetPoster(CurrentSource, DownloadFolder + pathsep + feedItems[i].Title.Replace(":", "") + pathsep);
 
                             //Delete the directory if it didn't download
                             if (tempBool == false && tempDirectoryCreated == true)
-                                Directory.Delete(DownloadFolder + @"\" + feedItems[i].Title.Replace(":", ""));
+                                Directory.Delete(DownloadFolder + pathsep + feedItems[i].Title.Replace(":", ""));
 
                         }
                         else
                         {
                             //Uncomment and remove when done debugging
-                            tempBool = GetTrailer(tempTrailerURL, feedItems[i].Title.Replace(":", ""), DownloadFolder + @"\");
+                            tempBool = GetTrailer(tempTrailerURL, feedItems[i].Title.Replace(":", ""), DownloadFolder + pathsep);
                             //tempBool = true;
                             //Assuming we downloaded the trailer OK and the config has been set to grab posters...
                             if (tempBool && GrabPoster)
-                                GetPoster(CurrentSource, DownloadFolder + @"\");
+                                GetPoster(CurrentSource, DownloadFolder + pathsep);
 
                         }
 
@@ -376,8 +376,8 @@ namespace HDTrailersNETDownloader
             else
                 fileName = trailerTitle + "_" + CurrentQualityPreference + ".mov";
 
-           
-            if (!File.Exists(downloadPath + @"\" + fileName))
+
+            if (!File.Exists(downloadPath + pathsep + fileName))
             {
 
                 try
@@ -392,7 +392,7 @@ namespace HDTrailersNETDownloader
                             Client.Headers.Add("Referer", "http://movies.yahoo.com/");
                         }
 
-                        Client.DownloadFile(downloadURL, downloadPath + @"\" + fileName);
+                        Client.DownloadFile(downloadURL, downloadPath + pathsep + fileName);
 
                         if (VerboseLogging)
                             WriteLog("Grab successful");
Coordinator
Feb 20, 2009 at 5:15 PM
Edited Feb 20, 2009 at 5:18 PM
Thanks! I've moved this to the Issue Tracker. I am making the changes manually to use Path.DirectorySeparatorChar but I notice that it looks like you used a tool to create a patch? Could you advise how I might load the patch and merge it into my code? There is an Upload Patch option on the Source Code tab. It looks like you were using something different though?

Thx again
Feb 23, 2009 at 12:24 AM
I use FreeBSD builtin command 'diff'' to generate diff file, and use 'patch' command to apply diff file.
In windows, WinMerge (http://WinMerge.org/) can generate diff file, in file compare view:
[menu]: Tools  -> Generate Patch dialog:
Choose style: Unified

I don't know how to apply diff file in windows, I'll search it later.

/Eric
Coordinator
Feb 23, 2009 at 1:30 AM
Thank you