Esempio n. 1
0
 /// <summary>
 /// Cleans-up any files left over in the program's temporary directory, from previous runs of the program.
 /// </summary>
 public static void CleanUpProgramTempDirectory()
 {
     try
     {
         string[] tempLinkFiles = Directory.GetFiles(
             UrlConverter.GetProgramTempDirectory(),
             Properties.Resources.StringLinkFileNameWildcard);
         foreach (string tempLinkFile in tempLinkFiles)
         {
             File.Delete(tempLinkFile);
         }
     }
     catch
     {
         // Clean-up operation exceptions should be invisible to the user, so ignore all exceptions.
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Get the target folder where to save the HTML link files. If Direct Mode, the target folder is in the /DIRECT=folder
        /// parameter. If not Direct Mode, the target folder is the program's temporary directory (and make sure it is created).
        /// Normally it should be located at "C:\Users\Aurelian\AppData\Local\Temp\HTMtied".
        /// </summary>
        /// <param name="isDirectMode">True if we are in Direct Mode, false otherwise.</param>
        /// <returns>The target folder pathname.</returns>
        private static string GetTargetFolder(out bool isDirectMode)
        {
            string targetFolder = string.Empty;

            // See if the command line contains the /DIRECT argument
            string directArg = Array.Find <string>(Environment.GetCommandLineArgs(), arg => arg.StartsWith(Properties.Resources.StringDirectParameter, StringComparison.OrdinalIgnoreCase));

            isDirectMode = !string.IsNullOrEmpty(directArg);
            if (isDirectMode)
            {
                // Get the target folder part from the /DIRECT=folder argument
                string[] parts = directArg.Split(new char[] { '=' }, 2);
                if (parts.Length == 2)
                {
                    targetFolder = parts[1];

                    // Try to create the Target folder if it does not exist
                    if (!Directory.Exists(targetFolder))
                    {
                        Directory.CreateDirectory(targetFolder);
                    }

                    // Return a correct and existing target folder for the Direct Mode
                    if (Directory.Exists(targetFolder))
                    {
                        return(targetFolder);
                    }
                }

                // We are in Direct Mode, but the target folder parameter is invalid, throw an exception
                throw new DirectoryNotFoundException();
            }
            else
            {
                targetFolder = UrlConverter.GetProgramTempDirectory();
            }

            return(targetFolder);
        }