Example #1
0
        internal static List<string> FindLanguages()
        {
            string[] a;
            var LstA = new List<string>();
            if (System.IO.Directory.Exists("Languages"))
            {
                a = System.IO.Directory.GetFiles("Languages", "*.ulex");
                foreach (var i in a)
                {
                    var u = new System.IO.FileInfo(i).Name;
                    u = u.Remove(u.LastIndexOf('.'));
                    LstA.Add(u);
                }
            }
            try
            {
                if (System.IO.Directory.GetFiles(Shared.LocalData("Languages")).Length > 0)
                {
                    a = System.IO.Directory.GetFiles(Shared.LocalData("Languages\\"), "*.ulex");
                    foreach (var i in a)
                    {
                        var u = new System.IO.FileInfo(i).Name;
                        u = u.Remove(u.LastIndexOf('.'));
                        if (LstA.Contains(u)) LstA.Remove(u);
                        LstA.Add(u);
                    }
                }
            }
            catch (Exception)
            {
                return LstA;
            }

            return LstA;
        }
Example #2
0
        public static string CreateDocument(string path, bool refresh)
        {
            try {
                string filePath, extn, name;
                int    s = 0;

                if (Directory.Exists(path))
                {
                    while (System.IO.File.Exists(filePath = (path + @"\File" + (++s).ToString() + ".txt")))
                    {
                        ;
                    }
                }
                else
                {
                    extn = new System.IO.FileInfo(path).Extension;
                    name = new System.IO.FileInfo(path).Name;
                    name = name.Substring(0, name.LastIndexOf(extn));

                    if (System.IO.File.Exists(filePath = path))
                    {
                        while (System.IO.File.Exists(filePath = (path.Substring(0, path.LastIndexOf(name)) + name + " (" + (++s).ToString() + ")" + extn)))
                        {
                            ;
                        }
                    }
                }
                System.IO.File.Create(filePath).Close();
                if (refresh)
                {
                    LoadFiles(path);
                }
                return(filePath);
            } catch (Exception) { throw; }
        }
 public List<Message> LoadMessagesFromFiles()
 {
     var result = new List<Message>();
     try
     {
         foreach (var fileName in Directory.GetFiles(ExecutablePath.ExecPath + folder, "*.txt"))
         {
             var shortName = new FileInfo(fileName).Name;
             var roomName = shortName.Substring(0, shortName.LastIndexOf(".txt"));
             lock (fileLock)
             {
                 using (var fs = new FileStream(fileName, FileMode.OpenOrCreate))
                 using (var sr = new StreamReader(fs))
                 {
                     var lineNumber = 0;
                     while (true)
                     {
                         var line = sr.ReadLine();
                         if (string.IsNullOrEmpty(line))
                             break;
                         var words = line.Split(new[] {"&#32;"}, StringSplitOptions.None);
                         if (words.Length < 4)
                         {
                             Logger.Error(string.Format("LoadMessagesFromFiles: format error: file: {0}, line: {1}", fileName, lineNumber));
                             lineNumber++;
                             continue;
                         }
                         var message = new Message
                             {
                                 TimeStamp = DateTime.Parse(words[0]),
                                 Sender = words[1].ToInt(),
                                 Room = roomName,
                                 Receiver = words[2].ToInt(),
                                 Text = words[3].Replace("&#10;", Environment.NewLine)
                             };
                         result.Add(message);
                         lineNumber++;
                     }
                 }
             }
         }
     }
     catch (Exception exception)
     {
         Logger.Info("ChatClientStorage.LoadMessagesFromFiles", exception);
     }
     return result;
 }
Example #4
0
 public InfoEFS(string fichero)
 {
     string b = fichero.Substring (0, fichero.LastIndexOf('.'));
     string c = fichero.Substring (fichero.LastIndexOf('.')+1);
     if (b==String.Empty){
         // TODO: Poner una excepcion personalizada.
         throw new Exception ("...");
     }
     string tmp = new FileInfo (fichero).Name;
     tmp = tmp.Substring (0, tmp.LastIndexOf('.'));
     nombreOriginal = tmp;
     string nf = c.Substring (0, c.LastIndexOf("_")).Trim();
     string f = c.Substring (c.LastIndexOf ("_") + 1).Trim();
     Fragmento = Convert.ToInt32 (f);
     totalFragmentos = Convert.ToInt32 (nf);
 }
Example #5
0
        public static void Gen()
        {
            var outputDirPath = @"..\Json";//System.IO.Path.Combine( Application.StartupPath, "Output" );
            if (!Directory.Exists(outputDirPath))
            {
                try
                {
                    Directory.CreateDirectory(outputDirPath);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.ReadKey();
                    return;
                }
            }
            foreach (var fn in Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "T_*.dll"))
            {
                var asm = Assembly.LoadFile(fn);
                var t = Helpers.GetTemplate(asm);
                var shortfn = new FileInfo(fn).Name;
                shortfn = shortfn.Substring(0, shortfn.LastIndexOf('.'));
                var path = outputDirPath;
                if (!Directory.Exists(path))
                {
                    try
                    {
                        Directory.CreateDirectory(path);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        Console.ReadKey();
                        return;
                    }
                }

                var rtv = JsonGen.Gen(t, path, shortfn.Substring("T_".Length));
                if (rtv)
                {
                    Console.WriteLine(rtv.ToString());
                    Console.ReadKey();
                    return;
                }
            }
        }
Example #6
0
        static void Main( string[] args )
        {
            var outputDirPath = System.IO.Path.Combine( Application.StartupPath, "Output" );
            if( !Directory.Exists( outputDirPath ) )
            {
                try
                {
                    Directory.CreateDirectory( outputDirPath );
                }
                catch( Exception ex )
                {
                    Console.WriteLine( ex.Message );
                    Console.ReadKey();
                    return;
                }
            }
            foreach( var fn in Directory.GetFiles( Application.StartupPath, "PacketTemplate_*.dll" ) )
            {
                var asm = Assembly.LoadFile( fn );
                var t = Helpers.GetTemplate( asm );
                var shortfn = new FileInfo( fn ).Name;
                shortfn = shortfn.Substring( 0, shortfn.LastIndexOf( '.' ) );
                var path = System.IO.Path.Combine( outputDirPath, shortfn.Replace( ".", "_" ) );
                if( !Directory.Exists( path ) )
                {
                    try
                    {
                        Directory.CreateDirectory( path );
                    }
                    catch( Exception ex )
                    {
                        Console.WriteLine( ex.Message );
                        Console.ReadKey();
                        return;
                    }
                }

                var rtv = GenCPP.Gen( t, path, shortfn.Substring( "PacketTemplate_".Length ) );
                if( rtv != "" )
                {
                    Console.WriteLine( rtv );
                    Console.ReadKey();
                    return;
                }
            }
        }
Example #7
0
        /// <summary>Determines whether this instance this instance can be started.</summary>
        /// <returns><c>true</c> if this instance can be started; otherwise <c>false</c>.</returns>
        private static bool CanStartThisInstance()
        {
            // check for the "newinstance" argument
            var forceNewInstance = false;

            foreach (var arg in Program.Arguments)
            {
                if (arg == ValidArgs.NewInstance)
                {
                    forceNewInstance = true;
                }
                else if (arg.StartsWith(ValidArgs.ParentProcId))
                {
                    var id = int.Parse(arg.Replace(ValidArgs.ParentProcId, "").Trim());
                    _parentProc  = Process.GetProcessById(id);
                    _isChildProc = true;
                }
            }

            if (forceNewInstance)
            {
                return(true);                  // force starting process
            }
            // check for a previous instance
            var appExeFile = new System.IO.FileInfo(AppPath).Name;

            appExeFile = appExeFile.Remove(appExeFile.LastIndexOf('.')); // remove the extension

            var procs    = Process.GetProcessesByName(appExeFile);
            var thisProc = Process.GetCurrentProcess();

            debuggerAttached = System.Diagnostics.Debugger.IsAttached;

            /*
             * Conditions for starting this instance:
             *  1. This is the only process
             *  2. More than one process and one of the existing processes is this one's parent
             *  3. A debugger is attached to this process
             */
            return((procs.Length == 1 && procs[0].Id == thisProc.Id) ||     // condition 1
                   (procs.Length > 1 && _parentProc != null &&
                    procs.Select(p => p.Id).Contains(_parentProc.Id)) ||    // condition 2
                   debuggerAttached);                                       // condition 3
        }
Example #8
0
        public static JoinInfo GetFromFile(string fichero)
        {
            JoinInfo info = new JoinInfo ();
            info.Directory = new FileInfo (fichero).Directory;
            string original = new FileInfo (fichero).Name;
            string extensionParte = original.Substring (original.LastIndexOf (".")+1);
            info.BaseName = original.Substring (0, original.LastIndexOf ('.') + 1);
            info.OriginalFile = original.Substring (0, original.LastIndexOf ('.'));

            // Soporte ultrasplit
            if (extensionParte.StartsWith ("u")) {
                info.BaseName = original.Substring (0, original.LastIndexOf ('.') + 2);
            }
            info.Digits = original.Length - info.BaseName.Length;

            if (File.Exists (info.Directory.FullName + Path.DirectorySeparatorChar + info.BaseName + UtilidadesCadenas.Format (0, info.Digits)))
            {
                info.InitialFragment = 0;
            }
            else if (File.Exists (info.Directory.FullName + Path.DirectorySeparatorChar + info.BaseName  + UtilidadesCadenas.Format (1, info.Digits)))
            {
                info.InitialFragment = 1;
            }
            else {
                return null;
            }
            int contador = 1;

            while (File.Exists (info.GetFragmentFullPath (contador)))
            {
                FileInfo fi = new FileInfo (info.GetFragmentFullPath (contador));
                info.Length += fi.Length;
                contador++;
            }
            info.FragmentsNumber = contador - 1;

            // Comprobar cutkiller
            if (info.InitialFragment == 1 && info.Digits == 3)
            {
                byte[] buffer = UtilidadesFicheros.LeerSeek (info.GetFragmentFullPath(1), 0, 8);
                string extension = UtArrays.LeerTexto (buffer, 0, 3);
                string fragmentos = UtArrays.LeerTexto (buffer, 3, 5);
                if (extension.Length > 0 && fragmentos.Length == 5)
                {
                    if (
                        Char.IsWhiteSpace (fragmentos[0]) &&
                        Char.IsWhiteSpace (fragmentos[1]) &&
                        Char.IsDigit (fragmentos[2]) &&
                        Char.IsDigit (fragmentos[3]) &&
                        Char.IsDigit (fragmentos[4]) &&
                        Int32.Parse (fragmentos.Trim ()) == info.FragmentsNumber

                    )
                    {
                        info.IsCutKiller = true;
                        info.OriginalFile = info.OriginalFile + "." + extension;
                        info.Length -= 8;
                    }
                }
            }
            info.CalculateLength();
            return info;
        }
        public async Task<bool> AddProjectInclude(string containerDirectory, string scriptFile = null)
        {
            if (!Project.Saved)
            {
                var saveDialogResult = MessageBox.Show(_ownerWindow, "Save pending changes to solution?",
                    "Save pending changes", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (saveDialogResult == DialogResult.OK || saveDialogResult == DialogResult.Yes)
                    _dte.SaveAll();
            }
            if (!Project.Saved || string.IsNullOrEmpty(Project.FullName))
            {
                var saveDialogResult = MessageBox.Show(_ownerWindow, "Pending changes need to be saved. Please save the project before adding project imports, then retry.", "Save first",
                    MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
                if (saveDialogResult != DialogResult.Cancel) _dte.SaveAll();
                return false;
            }
            _logger.LogInfo("Begin adding project import file");
            if (string.IsNullOrWhiteSpace(containerDirectory))
                containerDirectory = Project.GetDirectory();

            if (string.IsNullOrWhiteSpace(scriptFile))
            {
                _logger.LogInfo("Prompting for file name");
                var dialog = new AddBuildScriptNamePrompt(containerDirectory, ".targets")
                {
                    HideInvokeBeforeAfter = true
                };
                var dialogResult = dialog.ShowDialog(VsEnvironment.OwnerWindow);
                if (dialogResult == DialogResult.Cancel) return false;
                scriptFile = dialog.FileName;
                _logger.LogInfo("File name chosen: " + scriptFile);
                dialogResult = MessageBox.Show(_ownerWindow, @"        !! IMPORTANT !!

You must not move, rename, or remove this file once it has been added to the project. By adding this file you are extending the project file itself. If you must change the filename or location, you must update the project XML directly where <Import> references it.",
                    "This addition is permanent", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                if (dialogResult == DialogResult.Cancel) return false;
            }
            var scriptFileName = scriptFile;
            if (!scriptFile.Contains(":") && !scriptFile.StartsWith("\\\\"))
                scriptFile = Path.Combine(containerDirectory, scriptFile);
            var scriptFileRelativePath = FileUtilities.GetRelativePath(Project.GetDirectory(), scriptFile);
            var scriptFileShortName = new FileInfo(scriptFile).Name;
            if (scriptFileShortName.Contains("."))
                scriptFileShortName = scriptFileShortName.Substring(0, scriptFileShortName.LastIndexOf("."));

            if (Project == null) return false;

            File.WriteAllText(scriptFile, @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
    <Target Name=""" + scriptFileShortName + @"""><!-- consider adding attrib BeforeTargets=""Build"" or AfterTargets=""Build"" -->

        <!-- my tasks here -->
        <Message Importance=""high"" Text=""" + scriptFileShortName + @".targets output: ProjectGuid = $(ProjectGuid)"" />

    </Target>
</Project>");
            var projRoot = Project.GetProjectRoot();
            var import = projRoot.AddImport(scriptFileRelativePath);
            import.Condition = "Exists('" + scriptFileRelativePath + "')";
            Project = await Project.SaveProjectRoot();
            var addedItem = Project.ProjectItems.AddFromFile(scriptFile);
            addedItem.Properties.Item("ItemType").Value = "None";
            _logger.LogInfo("Project include file added to project: " + scriptFileName);
            Task.Run(() =>
            {
                System.Threading.Thread.Sleep(250);
                _dte.ExecuteCommand("File.OpenFile", "\"" + scriptFile + "\"");
            });
            return true;
        }
Example #10
0
        private void GetSelectedText()
        {
            int activeWinPtr = GetForegroundWindow().ToInt32();
               int activeThreadId = 0, processId;
               activeThreadId = GetWindowThreadProcessId(activeWinPtr, out processId);
               int currentThreadId = GetCurrentThreadId();
               //String prev = txtCmdLine.Text;
               if (activeThreadId != currentThreadId)
               {
               AttachThreadInput(activeThreadId, currentThreadId, true);
               SendCtrlC();
               System.Threading.Thread.Sleep(10);
               AttachThreadInput(activeThreadId, currentThreadId, false);
               ShowHide();
               if (Clipboard.ContainsText())
               {
                        HandleCmd(CmdInvoker.InvokeCommand("a "+Clipboard.GetText().Replace(Environment.NewLine," ")));
               }
               else if (Clipboard.ContainsFileDropList())
               {
                   for (int i = 0; i < Clipboard.GetFileDropList().Count; i++)
                   {
                       GGResult r;
                       String f = new FileInfo(Clipboard.GetFileDropList()[i]).Name;
                       if (f.Contains('.')) f = f.Substring(0, f.LastIndexOf('.'));
                       r = CmdInvoker.InvokeCommand("a \"" + f + "\"");
                       GGItem gg = CmdInvoker.GetGGList().GetGGItemAt(r.GetItemIndex());
                       HandleCmd(r);
                       HandleCmd(CmdInvoker.InvokeCommand("pin " + (CmdInvoker.GetGGList().IndexOfGGItem(gg) + 1) + " " + Clipboard.GetFileDropList()[i]));

                   }
               }
               //if (txtCmdLine.Text.Equals("a ")) txtCmdLine.Text = prev;
               }
        }
Example #11
0
        private static IEnumerable<int[]> GetUniqueCartesianProduct(string testName)
        {
            var files = Directory.GetFiles(string.Format(@"D:\test\MUTEX\CompleteComparison\sources\{0}", testName),
                                           @"main.c", SearchOption.AllDirectories).Select(p =>
                                                                                              {
                                                                                                  var dn =
                                                                                                      new FileInfo(p).
                                                                                                          DirectoryName;
                                                                                                  return
                                                                                                      Int32.Parse(
                                                                                                          dn.Substring(
                                                                                                              dn.LastIndexOf(
                                                                                                                  '\\') + 1));
                                                                                              }).ToList();

            var cp = from first in files
                     from second in files
                     orderby first , second
                     select new[] {first, second};

            var cartesianProduct = cp.Where(elem => elem[0] < elem[1]).ToList();
            return cartesianProduct;
        }
Example #12
0
 public void GetSourceMatchesGenerateZipFilePath(LeanDataLineTestParameters parameters)
 {
     var source = parameters.Data.GetSource(parameters.Config, parameters.Data.Time.Date, false);
     var normalizedSourcePath = new FileInfo(source.Source).FullName;
     var zipFilePath = LeanData.GenerateZipFilePath(Globals.DataFolder, parameters.Data.Symbol, parameters.Data.Time.Date, parameters.Resolution, parameters.TickType);
     var normalizeZipFilePath = new FileInfo(zipFilePath).FullName;
     var indexOfHash = normalizedSourcePath.LastIndexOf("#", StringComparison.Ordinal);
     if (indexOfHash > 0)
     {
         normalizedSourcePath = normalizedSourcePath.Substring(0, indexOfHash);
     }
     Assert.AreEqual(normalizeZipFilePath, normalizedSourcePath);
 }