Ejemplo n.º 1
0
 public void FileInfoEqualExperiment()
 {
     Console.WriteLine("[*] Start Experiment how the FileInfo.Equal Function work.");
     FileInfo file1 = new FileInfo(@"D:\CodeFolder\DotNet\Visual Studio 2013\Projects\ProcjetManager\ProcjetManager.sln");
     FileInfo file2 = new FileInfo(@"D:\CodeFolder\DotNet\Visual Studio 2013\Projects\ProcjetManager\ProcjetManager.sln");
     FileInfo file3 = new FileInfo(@"D:\CodeFolder\DotNet\Visual Studio 2013\Projects\ProcjetManager\ProcjetManager.v12.suo");
     Console.WriteLine("-- Run FileInfo.Equal with to FileInfos have the same FullName : " + file1.Equals(file2));
     Console.WriteLine("   FullName1 is [" + file1.FullName + "]");
     Console.WriteLine("   FullName2 is [" + file2.FullName + "]");
     Console.WriteLine("-- Run FileInfo.Equal with to FileInfos have fiffrent FullNames : " + file1.Equals(file3));
     Console.WriteLine("   FullName1 is [" + file1.FullName + "]");
     Console.WriteLine("   FullName2 is [" + file3.FullName + "]");
     Console.WriteLine("[*] End Experiment how the FileInfo.Equal Function work.");
 }
        /// <summary> How to keep track of all the modified times
        /// across the paths.  Note that a file might have
        /// appeared in a directory which is earlier in the
        /// path; so we should search the path and see if
        /// the file we find that way is the same as the one
        /// that we have cached.
        /// </summary>
        /// <param name="resource">
        /// </param>
        /// <returns> True if the source has been modified.
        /// </returns>
        public override bool IsSourceModified(Resource resource)
        {
            /*
             * we assume that the file needs to be reloaded;
             * if we find the original file and it's unchanged,
             * then we'll flip this.
             */
            bool modified = true;

            string fileName = resource.Name;
            string path     = (string)templatePaths[fileName];

            System.IO.FileInfo currentFile = null;

            for (int i = 0; currentFile == null && i < paths.Count; i++)
            {
                string             testPath = (string)paths[i];
                System.IO.FileInfo testFile = GetFile(testPath, fileName);

                if (testFile.Exists)
                {
                    currentFile = testFile;
                }
            }
            System.IO.FileInfo file = GetFile(path, fileName);

            if (currentFile == null || !file.Exists)
            {
                /*
                 * noop: if the file is missing now (either the cached
                 * file is gone, or the file can no longer be found)
                 * then we leave modified alone (it's set to true); a
                 * reload attempt will be done, which will either use
                 * a new template or fail with an appropriate message
                 * about how the file couldn't be found.
                 */
            }
            else
            {
                if (currentFile.Equals(file))
                {
                    /*
                     * if only if currentFile is the same as file and
                     * file.lastModified() is the same as
                     * resource.getLastModified(), then we should use the
                     * cached version.
                     */

                    modified = (((file.LastWriteTime.Ticks - 621355968000000000) / 10000) != resource.LastModified);
                }
            }

            /*
             * rsvc.Debug("isSourceModified for " + fileName + ": " + modified);
             */
            return(modified);
        }
Ejemplo n.º 3
0
        public static String MakeRelative(String path, String fromPath)
        {
            List<String> pathComponents = new List<String>();

            if (fromPath == null)
            {
                return path;
            }

            /* Use FileSystemInfo to canonicalize paths, ensure fromPath ends in a trailing \ to fromPath. */
            path = new FileInfo(path).FullName;
            fromPath = new FileInfo(fromPath + @"\").FullName;

            if (fromPath.Equals(new FileInfo(path + @"\").FullName))
            {
                return ".";
            }

            /* Find the longest common base directory */
            String baseDirectory = null;

            for (int i = 0, lastSeparatorIdx = -1; ; i++)
            {
                if (i == path.Length || i == fromPath.Length || path[i] != fromPath[i])
                {
                    baseDirectory = (lastSeparatorIdx >= 0) ? path.Substring(0, lastSeparatorIdx + 1) : null;
                    break;
                }
                else if (path[i] == Path.DirectorySeparatorChar)
                {
                    lastSeparatorIdx = i;
                }
            }

            /* No common directories (on different drives), no relativization possible */
            if (baseDirectory == null)
            {
                return path;
            }

            /* Find the distance from the relativeFromPath to the baseDirectory */
            String fromRelativeToBase = fromPath.Substring(baseDirectory.Length);
            for (int i = 0; i < fromRelativeToBase.Length; i++)
            {
                if (fromRelativeToBase[i] == Path.DirectorySeparatorChar)
                {
                    pathComponents.Add("..");
                }
            }

            /* Add the path portion relative to the base */
            pathComponents.Add(path.Substring(baseDirectory.Length));

            return String.Join(new String(new char[] { Path.DirectorySeparatorChar }), pathComponents.ToArray());
        }
Ejemplo n.º 4
0
		/// <summary>
		/// Finds a project item in the received IVsHierarchy, given its name.
		/// </summary>
		/// <param name="projectHierarchy">The IVsHierarchy to start the search.</param>
		/// <param name="name">The name of the item to locate.</param>
		/// <returns>A <see cref="Project"/> reference or <see langword="null" /> if 
		/// it doesn't exist. Project can be C# or VB.</returns>
		public static uint FindItemByName(IVsHierarchy projectHierarchy, string name)
		{
			uint foundItemID = VSConstants.VSITEMID_NIL;
			EnumHierarchyItems(projectHierarchy,
				delegate(IVsHierarchy hierarchy, uint itemid, int recursionLevel)
				{
					string itemName = null;
					hierarchy.GetCanonicalName(itemid, out itemName);
					if (itemName!=null)
					{
						itemName = new FileInfo(itemName).Name;
						if (itemName.Equals(name))
						{
							foundItemID = itemid;
							return false;
						}
					}
					return true;
				});

			return foundItemID;
		}
      //C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2015

      public void Initialize() {
         var commonStartMenupath = Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu);

         var programsDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"Microsoft\Windows\Start Menu\Programs");
         var shortcuts = Directory.GetFiles(programsDirectory, "*", SearchOption.AllDirectories).Concat(Directory.GetFiles(commonStartMenupath, "*", SearchOption.AllDirectories));
         foreach (var shortcut in shortcuts) {
//            Console.WriteLine(shortcut); 
            var fileInfo = new FileInfo(shortcut);
            if (fileInfo.Extension.Equals(".lnk", StringComparison.OrdinalIgnoreCase)) {
               var happyName = fileInfo.Name.Substring(0, fileInfo.Name.Length - fileInfo.Extension.Length);
               if (!commands.Any(x => x.Equals(happyName, StringComparison.OrdinalIgnoreCase))) {
                  commands = commands.Concat(new[] { happyName }).ToArray();
                  linkPathsByCommand.Add(happyName, shortcut);

                     // WshShellClass shell = new WshShellClass();
                     WshShell shell = new WshShell(); //Create a new WshShell Interface
                     IWshShortcut link = (IWshShortcut)shell.CreateShortcut(shortcut); //Link the interface to our shortcut

                  if (File.Exists(link.TargetPath)) {
                     var icon = Icon.ExtractAssociatedIcon(link.TargetPath);
                     var bmp = icon.ToBitmap();
                     iconsByCommandHappy.Add(happyName, bmp);

                     var fileName = new FileInfo(link.TargetPath).Name;
                     Console.WriteLine(fileName);
                     if (!fileName.Equals(happyName + ".exe", StringComparison.OrdinalIgnoreCase) &&
                         !commands.Any(x => x.Equals(fileName, StringComparison.OrdinalIgnoreCase))) {
                        commands = commands.Concat(new[] { fileName }).ToArray();
                        exectuablesByFileName.Add(fileName, link.TargetPath);
                     iconsByFileName.Add(fileName, bmp);
                     }
                  } else {
                     var icon = Icon.ExtractAssociatedIcon(shortcut);
                     var bmp = icon.ToBitmap();
                     iconsByCommandHappy.Add(happyName, bmp);
                  }
               }
            }
         }
      }
Ejemplo n.º 6
0
        public void DownloadFiles(object sender, AsyncCompletedEventArgs e)
        {
            //We stop the stopwatch.
            //sw.Stop();
            try
            {
                for (int intCurrFile = sucessfullyDownloadedCount; intCurrFile < FileAddressList.GetLength(0); intCurrFile++)
                {
                    sw.Reset();
                    Application.DoEvents();
                    if (FileAddressList[intCurrFile,0] == null)
                    {
                        break;
                    }
                    CurrentFileDLName = Path.GetFileName((new Uri(FileAddressList[intCurrFile, 0])).AbsolutePath);
                    label8.Text = "Part " + (intCurrFile + 1) + " of " + FileAddressList.GetLength(0);
                    progressBar2.Value = 100 * intCurrFile / FileAddressList.GetLength(0);
                    if (cVersion.IsMlkSimAC3Package(CurrentFileDLName) && ActionNextLabel.Text == "Action: uninstall, but keep songs, then install updates")
                        continue;
                    if (File.Exists(Path.Combine(TempPath, CurrentFileDLName)))
                    {
                        string GenByte = new System.IO.FileInfo(Path.Combine(TempPath, CurrentFileDLName)).Length.ToString();
                        //if it match, then we download the next file!
                        if (FileAddressList[intCurrFile, 1].Equals(GenByte) == false && GenByte.Equals("483491840") ==false)
                        {
                            // Delete the file if it exist.
                            if (File.Exists(Path.Combine(TempPath, CurrentFileDLName))) { File.Delete(Path.Combine(TempPath, CurrentFileDLName)); }
                            // Ask user to redownload or cancel.
                            if (DownloadRetryCount < 5)
                            {
                                Downloaded = null;
                                Downloaded2 = null;
                                GenByte = null;
                                Timeout.Stop();
                                DownloadRetryCount += 1;
                                DownloadAndInstallButton_Click(null, null);
                                break;
                            }
                            else
                            {
                                DownloadRetryCount = 3;
                                DialogResult dialogResult = MessageBox.Show("the downloaded file " + CurrentFileDLName + " is corrupted. Please make sure you use a stable internet connection. Do you want to retry downloading?", "File verification FAILED", MessageBoxButtons.YesNo);
                                if (dialogResult == DialogResult.Yes)
                                {
                                    Downloaded = null;
                                    Downloaded2 = null;
                                    GenByte = null;
                                    Timeout.Stop();
                                    DownloadAndInstallButton_Click(null, null);
                                    break;
                                }
                                else if (dialogResult == DialogResult.No)
                                {
                                    cHelper.ShowErrorMessageDialog("User aborted after corruped file downloads. Closing application now.", "", "");
                                    break;
                                }
                            }
                        }
                        else
                        {
                            sucessfullyDownloadedCount = Math.Max(sucessfullyDownloadedCount, (intCurrFile+1));
                        }
                    }
                    // If the file doesn't exist or has been detected as incorrect and deleted, we QUACK a copy!
                    else
                    {
                        Canard = new WebClient();
                        Canard.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFiles);
                        Canard.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);

                        sw.Start();
                        Canard.DownloadFileAsync(new Uri(FileAddressList[intCurrFile, 0]), Path.Combine(TempPath, CurrentFileDLName));
                        progressBar1.Value = 0;
                        break;
                    }
                }
                if (sucessfullyDownloadedCount == FileAddressList.GetLength(0))
                {
                    //all files are now successfully downloaded.
                    progressBar2.Value = 100;
                    InstallationFunctionThread();
                }
                //We start the stopwatch to calculate progress.
            }
            catch (Exception ex)
            {
                cHelper.ShowErrorMessageDialog(ex.Message, ex.StackTrace, "DownloadFiles");
            }
        }
        /// <summary>
        /// Retrieves a file from the destination and copies it to the specified path.
        /// </summary>
        /// <param name="fromPath">the file to retrieve from the destination (relative to basePath)</param>
        /// <param name="toPath">the local location to save the contents of the file (fully-qualifed path)</param>
        /// <param name="isBinary">true if the file is binary</param>
        override public bool GetFile(String fromPath, string toPath, bool isBinary)
        {
            fromPath = Path.Combine(m_path, fromPath);
            FileInfo fromFile = new FileInfo(fromPath);
            FileInfo toFile = new FileInfo(fromPath);
            if (fromFile.Equals(toFile))
            {
                //then the source is the same as the destination, so ignore
                return true;
            }

            try
            {
                // Delete existing file
                if (File.Exists(toPath))
                    File.Delete(toPath);

                // Copy the file
                File.Copy(fromPath, toPath);

                return true;
            }
            catch (Exception e)
            {
                if (RetryOnException(e))
                    return false;
                else
                {
                    SiteDestinationException ex = new SiteDestinationException(e, SiteDestinationException.TransferException, GetType().Name, 0);
                    ex.DestinationExtendedMessage = e.Message;
                    throw ex;
                }
            }
        }
Ejemplo n.º 8
0
 public static bool AreEqual(string path1, string path2)
 {
     var fullName = new System.IO.FileInfo(path1).FullName;
     var fullName2 = new System.IO.FileInfo(path2).FullName;
     return fullName.Equals(fullName2, StringComparison.InvariantCultureIgnoreCase);
 }