/// <summary>
        /// Enumerate source files in the folder and run the formatting process
        /// </summary>
        /// <param name="RootPath"></param>
        private static void Execute(string RootPath)
        {
            foreach (string DirPath in Directory.EnumerateDirectories(RootPath))
            {
                string FolderName = Path.GetFileName(DirPath);
                if (IgnoredFolders.Contains(FolderName.ToLower()))
                {
                    continue;
                }

                foreach (string FilePath in Directory.EnumerateFiles(DirPath))
                {
                    string FileName = Path.GetFileName(FilePath);
                    if (!IgnoredFiles.Contains(FileName.ToLower()))
                    {
                        string FileExt = Path.GetExtension(FilePath);
                        if (SourceExts.Contains(FileExt.ToLower()) && !FilePath.Contains(".Designer."))
                        {
                            Console.WriteLine(FilePath);
                            ProcessSourceFile(FilePath);
                        }
                    }
                }

                Execute(DirPath);
            }
        }
Example #2
0
        /// <summary>
        /// Event that calls the method to Generate the NetWork and Grafcet
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btn_GenerateNetNGraf_Click(object sender, RoutedEventArgs e)
        {
            bool importToTia = (bool)cbImportToTia.IsChecked;

            if (FilePath.Contains(".xlsx") || FilePath.Contains(".xlsm") || FilePath.Contains(".xltx") || FilePath.Contains(".xltm"))
            {
                WriteSavingLabelText("Generating NetNGraf...");

                BlocksCreated = new List <string>();
                RetrieveValues();

                // Update lists "SheetsStepS" and "SheetsNameS"
                foreach (WorkSheet ws in workSheets)
                {
                    if (ws.WorkSheetSteps.Count() > 1)
                    {
                        SaveWorksheetIntoMatrix(ws, ws.WorkSheetName);
                    }
                    else
                    {
                        MessageBox.Show("Worksheet \"" + ws.WorkSheetName + "\" will not be generated because it does not have sufficient steps.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                UpdateWorksheetSteps();

                PlcSoftware plcS = null;

                GrafcetManager.SavePath = Path.Combine(savePath, "50_Stationen");

                if (current != null)
                {
                    plcS = (PlcSoftware)(current as PlcBlockUserGroup).Parent.Parent;
                }

                try
                {
                    GrafcetManager.GenerateGrafcet(sheetsStepS, sheetsNameS, plcS);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    WriteSavingLabelText("");
                    return;
                }

                if (importToTia)
                {
                    BlocksCreated = BlocksCreated.Distinct().ToList();
                    using (var access = tiaPortal.ExclusiveAccess("Importing elements"))
                    {
                        ExcelManager.BlocksImporter(savePath, current, "50_Stationen", BlocksCreated);
                    }
                }

                Changes = true;
                WriteSavingLabelText("");
            }
        }
Example #3
0
        /// <summary>
        /// Uses polymorphic features of the IDataType interface to save the different data types differently
        /// Headers for all types of files match, save for the first 3 bytes, which use the file extension to
        ///		save the proper string.
        /// </summary>
        /// <param name="pubVersion">Version of the pub file to save. For Ethan's client, items should be 1, otherwise, this should be 0 (for now)</param>
        /// <param name="error">ref parameter that provides the Exception.Message string on an error condition</param>
        /// <returns>True if successful, false on failure. Use the 'error' parameter to check error message</returns>
        public bool Save(int pubVersion, ref string error)
        {
            try
            {
                using (FileStream sw = File.Create(FilePath))                 //throw exceptions on error
                {
                    if (FilePath.Length <= 4 || !FilePath.Contains('.'))
                    {
                        throw new ArgumentException("The filename of the data file must have a 3 letter extension. Use EIF, ENF, ESF, or ECF.");
                    }

                    //get the extension to write as the first 3 bytes
                    byte[] extension = Encoding.ASCII.GetBytes(FilePath.ToUpper().Substring(FilePath.LastIndexOf('.') + 1));
                    if (extension.Length != 3)
                    {
                        throw new ArgumentException("The filename of the data file must have a 3 letter extension. Use EIF, ENF, ESF, or ECF.");
                    }

                    //allocate the data array for all the data to be saved
                    byte[] allData;
                    //write the file to memory first
                    using (MemoryStream mem = new MemoryStream())
                    {
                        mem.Write(extension, 0, 3);                          //E[I|N|S|C]F at beginning
                        mem.Write(Packet.EncodeNumber(Rid, 4), 0, 4);        //rid
                        mem.Write(Packet.EncodeNumber(Data.Count, 2), 0, 2); //len

                        Version = pubVersion;
                        mem.WriteByte(Packet.EncodeNumber(Version, 1)[0]);                         //new version check

                        for (int i = 1; i < Data.Count; ++i)
                        {
                            byte[] toWrite = Data[i].SerializeToByteArray();
                            mem.Write(toWrite, 0, toWrite.Length);
                        }
                        allData = mem.ToArray();                         //get all data bytes
                    }

                    //write the data to the stream and overwrite whatever the rid is with the CRC
                    CRC32 crc    = new CRC32();
                    uint  newRid = crc.Check(allData, 7, (uint)allData.Length - 7);
                    Rid = (int)newRid;
                    sw.Write(allData, 0, allData.Length);
                    sw.Seek(3, SeekOrigin.Begin);                     //skip first 3 bytes
                    sw.Write(Packet.EncodeNumber(Rid, 4), 0, 4);      //overwrite the 4 RID (revision ID) bytes
                }
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return(false);
            }

            error = "none";
            return(true);
        }
        /// <summary>
        /// Loads cars into an ArrayList. The .txt file with cars is set at startup. If user doesn't specify, it's defaultCarLot.txt.
        /// </summary>
        public void LoadCars()
        {
            List <Car> carList = new List <Car>();

            try
            {
                string[] lines = File.ReadAllLines(FilePath);
                foreach (string line in lines)
                {
                    string[]     parts    = line.Split('\t');
                    Car.FuelEnum thisFuel = (Car.FuelEnum)Enum.Parse(typeof(Car.FuelEnum), parts[5]);
                    carList.Add(new Car(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2]), parts[3], parts[4], thisFuel,
                                        decimal.Parse(parts[6]), parts[7], int.Parse(parts[8]), bool.Parse(parts[9])));
                }
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine("The file you tried to load is missing.\n" +
                                  "A new empty database file will be created.\n" +
                                  "Press any key to continue");
                Console.ReadKey();
                if (!FilePath.Contains(".txt"))
                {
                    FilePath += ".txt";
                }
            }
            catch (Exception)
            {
                FilePath = CreateFilePath();
                Console.WriteLine("The file you tried to load is corrupted or the data in it doesn't fit the required format.\n" +
                                  $"A new empty database file was created named {FilePath}\n" +
                                  "Press any key to continue");
                Console.ReadKey();
                FilePath = CreateFilePath();
            }


            if (carList.Count != 0)
            {
                Console.WriteLine("The following cars have been successfully loaded from the database:");
                foreach (var car in carList)
                {
                    Console.WriteLine(car.ToString());
                }
            }
            else
            {
                Console.WriteLine("Your text file is empty.");
            }

            Console.WriteLine("Press any key to return to the main menu.");
            Console.ReadKey();
            Console.Clear();
            carDatabase = carList;
            Incrementor = getHighestID();
        }
Example #5
0
        public void LoadLevelInfo()
        {
            if (Directory.Exists(".\\Levels"))
            {
                string[] strDirectories = Directory.GetDirectories(".\\Levels");
                //string[] strfileEntries = Directory.GetFiles(".\\Levels");
                string Klappa = "";
                foreach (string DirPath in strDirectories)
                {
                    Klappa += DirPath + "\n";

                    LevelInfo lvlInfo = new LevelInfo();
                    lvlInfo.SetLevelNumber(_LevelInfos);
                    _LevelInfos++;
                    if (File.Exists(DirPath + "\\info.txt"))
                    {
                        // Open the text file using a stream reader.
                        using (StreamReader sr = new StreamReader(DirPath + "\\info.txt"))
                        {
                            // Read the stream to a string, and add to level info class.
                            String line = sr.ReadLine();
                            lvlInfo.SetName(line);
                            Klappa += "\n" + line + "\n";
                        }

                        Klappa += DirPath + "\\info.txt" + "\n";
                    }

                    string[] strFiles = Directory.GetFiles(DirPath + "\\");
                    foreach (string FilePath in strFiles)
                    {
                        if (FilePath.Contains("info.txt") || !FilePath.Contains(".txt"))
                        {
                            continue;
                        }

                        lvlInfo.LoadLevel(FilePath);
                        Klappa += FilePath + "\n";
                    }

                    _lstLevelInfos.Add(lvlInfo);
                }


                //MessageBox.Show(Klappa, "1");
            }
            else
            {
                mainWindowForm.DialogAddLink("Click", "https://github.com/yamiM0NSTER/Sudoku-PO/blob/master/Levels_Help");
                mainWindowForm.ShowDialogForm(mainWindowForm, "OOPS!", "Levels Folder is missing.\n Click the link below to see how to fix that.");

                //MessageBox.Show("Kappa", "0");
            }
        }
Example #6
0
        /// <summary>
        ///     Checks if this AudioTaskItem is valid.
        /// </summary>
        /// <returns>true if valid, false instead.</returns>
        public bool ItemIsValid()
        {
            // Always return true for built-in sound
            var arraySpecialAudios = new[] {
                "$SILENCE_AUDIO$", "$BEEP_SOUND$", "$GREENSLEEVES_"
            };

            foreach (var specialAudio in arraySpecialAudios)
            {
                if (FilePath.Contains(specialAudio))
                {
                    return(true);
                }
            }

            return(File.Exists(FilePath));
        }
Example #7
0
        private void StartProcess()
        {
            try
            {
                // SpecialFolder 경로 취득
                var matches = Regex.Matches(FilePath, @"\{(.*?)\}");
                foreach (Match m in matches)
                {
                    string origin = m.Groups[0].ToString();

                    Environment.SpecialFolder folder;
                    if (!Enum.TryParse(m.Groups[1].ToString(), true, out folder))
                    {
                        continue;
                    }
                    string realPath = Environment.GetFolderPath(folder);
                    FilePath = FilePath.Replace(origin, realPath);
                }

                var si = new ProcessStartInfo();
                si.FileName = FilePath;

                // 네트워크 연결
                if (!FilePath.Contains("://"))
                {
                    if (StartWithAdministrator)
                    {
                        si.UseShellExecute = true;
                        si.Verb            = "runas";
                    }
                    si.Arguments        = Arguments;
                    si.WorkingDirectory = Path.GetDirectoryName(FilePath);
                }

                var proc = new Process();
                proc.StartInfo = si;
                proc.Start();
            }
            catch (Exception ex)
            {
                MessageBoxUtil.Error(ex.Message);
            }
        }
        /// <summary>
        /// 保存按钮执行的动作
        /// </summary>
        private void SaveClick()
        {
            List <string> files = null;

            Controller.Convertor.ErrorType errors = Controller.Convertor.ErrorType.NoErros;
            IsInProgress = true;

            if (!System.IO.Directory.Exists(FilePath))
            {
                swApp.SendMsgToUser("当前路径不存在:" + FilePath);
                return;
            }
            if (FilePath.Contains("-") || FileName.Contains("-"))
            {
                swApp.SendMsgToUser("-为非法字符,路径或者文件民包含-字符,请修改路径或者文件名后重新保存");
                return;
            }
            try
            {
                //会堵塞UI;TODO:异步方式实现转换
                var model = Controller.Convertor.DuConvertor.ConvertToglTFModel(swModel, out errors);
                if (model != null)
                {
                    files = Controller.Convertor.DuConvertor.SaveAs(model, FilePath, FileName);
                }
                swApp.SendMsgToUser("保存完成");
                if (files != null && IsOpenFile && files.Count >= 3)
                {
                    System.Diagnostics.Process.Start(files[2]);
                }
                if (IsOpenFolder)
                {
                    System.Diagnostics.Process.Start("explorer.exe", FilePath);
                }
                IsInProgress = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            // System.Diagnostics.Process.Start("ExpLore", "C:\\window");
        }
Example #9
0
        public FileReader GetDataFile()
        {
            if (DataReader != null)
            {
                return(DataReader);
            }

            if (IFileInfo.ArchiveParent != null)
            {
                foreach (var file in IFileInfo.ArchiveParent.Files)
                {
                    if (file.FileName.Contains("DATA1.bin"))
                    {
                        return(new FileReader(file.FileDataStream, true));
                    }
                }
            }
            else
            {
                string path = "";
                if (FilePath.Contains("LINKDATA.IDX"))
                {
                    path = FilePath.Replace("IDX", "BIN");
                }

                if (FilePath.Contains("DATA0.bin"))
                {
                    path = FilePath.Replace("DATA0", "DATA1");
                }

                if (!System.IO.File.Exists(path))
                {
                    throw new Exception("Failed to find data path! " + path);
                }

                return(new FileReader(path, true));
            }

            return(null);
        }
Example #10
0
        public bool Update()
        {
            try
            {
                string html = _httpClient.GetStringAsync($"http://{_IP}:{_port}/variables.html").Result;

                HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                doc.LoadHtml(html);

                FileName = Path.GetFileNameWithoutExtension(doc.GetElementbyId("file").InnerText);
                FilePath = doc.GetElementbyId("filedir").InnerText;

                VideoTime = Int64.Parse(doc.GetElementbyId("position").InnerText);

                //Get file from Kodi if MPC looks like it is a mounted ISO.
                if (FilePath.Contains(@"\BDMV"))
                {
                    GetFileFromKodi();
                }

                if (doc.GetElementbyId("statestring").InnerText == "Playing")
                {
                    IsPlaying = true;
                }
                else
                {
                    IsPlaying = false;
                }
            }
            catch
            {
                ErrorStatus = $"({DateTime.Now:h:mm:ss tt}) Cannot connect to MPC at: {_IP}:{_port}";
                return(false);
            }

            return(true);
        }
Example #11
0
    static void UploadDirectoryToProject(OneSky.Project project, DirectoryInfo directory, string fileExtension)
    {
        DirectoryInfo[] cultureDirectories = directory.GetDirectories("*", SearchOption.TopDirectoryOnly);

        // Upload, synchronously, the base culture POs.
        DirectoryInfo nativeCultureDirectory = Array.Find(cultureDirectories, d => { return(string.Equals(d.Name, project.BaseCultureName, StringComparison.InvariantCultureIgnoreCase)); });

        if (nativeCultureDirectory != null)
        {
            string[] files = Directory.GetFiles(nativeCultureDirectory.FullName, fileExtension, SearchOption.AllDirectories);
            UploadFilesToProjectForLocale(project, files.Where((FilePath) => { return(!FilePath.Contains("_FromOneSky")); }).ToArray(), nativeCultureDirectory.Name);
        }

        // Upload all other POs asynchronously.
        foreach (var foreignCultureDirectory in Array.FindAll(cultureDirectories, d => { return(d != nativeCultureDirectory); }))
        {
            string[] files = Directory.GetFiles(foreignCultureDirectory.FullName, fileExtension, SearchOption.AllDirectories);
            UploadFilesToProjectForLocale(project, files.Where((FilePath) => { return(!FilePath.Contains("_FromOneSky")); }).ToArray(), foreignCultureDirectory.Name);
        }
    }
Example #12
0
        /// <summary>
        /// Saves the current DataGrid values in the chosen path
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btn_Save_Click(object sender, RoutedEventArgs e)
        {
            WriteSavingLabelText("Saving...");

            if (ExcelManager.IsOpened(FilePath))
            {
                MessageBox.Show("Please close the current workbook before saving");
            }
            else
            {
                RetrieveValues();

                if (FilePath.Contains(".xlsx") || FilePath.Contains(".xlsm") || FilePath.Contains(".xltx") || FilePath.Contains(".xltm"))
                {
                    Excel.Application xlApp = new Excel.Application
                    {
                        DisplayAlerts = false
                    };
                    Workbook xlWorkbook = xlApp.Workbooks.Open(FilePath);
                    int      row        = 4;
                    var      matrixs    = new List <object[, ]>();
                    var      sheetNames = new List <string>();

                    foreach (Worksheet sheet in xlWorkbook.Worksheets)
                    {
                        string sheetName = sheet.Name;
                        if (!sheetName.Contains("AS_") || sheetName.Equals("AS_000000"))
                        {
                            continue;
                        }

                        object[,] matrix = OpennessHelper.ExcelToMatrix(sheet);
                        if (sheet.Name.Contains(ComboSheet.SelectedItem.ToString()))
                        {
                            Ws = sheet;
                            while (Ws.Cells[row, 3].Value != null)
                            {
                                Ws.Cells[row, 3].Value = null;
                                Ws.Cells[row, 4].Value = null;
                                Ws.Cells[row, 5].Value = null;
                                Ws.Cells[row, 6].Value = null;
                                Ws.Cells[row, 7].Value = null;
                                Ws.Cells[row, 8].Value = null;

                                row += 1;
                            }

                            row = 4;

                            foreach (Step step in steps)
                            {
                                Ws.Cells[row, 2].Value = step.StepNumber;
                                Ws.Cells[row, 3].Value = step.Schritt.Replace(" ", string.Empty);
                                Ws.Cells[row, 4].Value = step.Beschreibung;
                                Ws.Cells[row, 5].Value = step.Aktion.Replace(" ", string.Empty);
                                Ws.Cells[row, 6].Value = step.Vorheriger_Schritt.Replace(" ", string.Empty);
                                Ws.Cells[row, 7].Value = step.Nächster_Schritt.Replace(" ", string.Empty);
                                Ws.Cells[row, 8].Value = step.Zeit_Schritt.ToLower().Replace(" ", string.Empty).Replace("ms", string.Empty);

                                matrix[row, 2] = step.StepNumber;
                                matrix[row, 3] = step.Schritt.Replace(" ", string.Empty);
                                matrix[row, 4] = step.Beschreibung;
                                matrix[row, 5] = step.Aktion.Replace(" ", string.Empty);
                                matrix[row, 6] = step.Vorheriger_Schritt.Replace(" ", string.Empty);
                                matrix[row, 7] = step.Nächster_Schritt.Replace(" ", string.Empty);
                                matrix[row, 8] = step.Zeit_Schritt.ToLower().Replace(" ", string.Empty).Replace("ms", string.Empty);

                                row += 1;
                            }
                        }
                        matrixs.Add(matrix);
                        sheetNames.Add(sheet.Name);
                    }

                    MatrixList(matrixs);
                    SheetNamesList(sheetNames);

                    xlWorkbook.Save();
                    xlWorkbook.Close(0);
                    xlApp.Quit();

                    sheetsStepS = new List <object[, ]>();
                    foreach (var m in matrixs)
                    {
                        sheetsStepS.Add(m);
                    }
                    sheetsNameS = new List <string>();
                    foreach (var n in sheetNames)
                    {
                        sheetsNameS.Add(n);
                    }

                    Saving.Text = "";
                    Saving.Update();

                    if (Ws == null)
                    {
                        System.Windows.MessageBox.Show("This Excel does not contain a usable worksheet", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }

            WriteSavingLabelText("");
        }
Example #13
0
        /// <summary>
        /// Uses polymorphic features of the IDataType interface to save the different data types differently
        /// Headers for all types of files match, save for the first 3 bytes, which use the file extension to
        ///		save the proper string.
        /// </summary>
        /// <param name="pubVersion">Version of the pub file to save. For Ethan's client, items should be 1, otherwise, this should be 0 (for now)</param>
        /// <param name="error">ref parameter that provides the Exception.Message string on an error condition</param>
        /// <returns>True if successful, false on failure. Use the 'error' parameter to check error message</returns>
        public bool Save(int pubVersion, ref string error)
        {
            try
            {
                using (FileStream sw = File.Create(FilePath))                 //throw exceptions on error
                {
                    if (FilePath.Length <= 4 || !FilePath.Contains('.'))
                    {
                        throw new ArgumentException("The filename of the data file must have a 3 letter extension. Use EIF, ENF, ESF, or ECF.");
                    }

                    //get the extension to write as the first 3 bytes
                    byte[] extension = Encoding.ASCII.GetBytes(FilePath.ToUpper().Substring(FilePath.LastIndexOf('.') + 1));
                    if (extension.Length != 3)
                    {
                        throw new ArgumentException("The filename of the data file must have a 3 letter extension. Use EIF, ENF, ESF, or ECF.");
                    }

                    //allocate the data array for all the data to be saved
                    //this is done based on the type of the Data items
                    byte[] allData;
                    if (Data.Count > 0)
                    {
                        if (Data[0] is ItemRecord)
                        {
                            allData = new byte[10 + ItemFile.DATA_SIZE * Data.Count];
                        }
                        else if (Data[0] is NPCRecord)
                        {
                            allData = new byte[10 + NPCFile.DATA_SIZE * Data.Count];
                        }
                        else if (Data[0] is SpellRecord)
                        {
                            allData = new byte[10 + SpellFile.DATA_SIZE * Data.Count];
                        }
                        else if (Data[0] is ClassRecord)
                        {
                            allData = new byte[10 + ClassFile.DATA_SIZE * Data.Count];
                        }
                        else
                        {
                            throw new ArgumentException("The internal data container has records of invalid type. Memory is corrupted.");
                        }
                    }
                    else
                    {
                        throw new IndexOutOfRangeException("There are no data items to save!");
                    }

                    //write the file to memory first (wrapper around allData byte array)
                    using (MemoryStream mem = new MemoryStream(allData))
                    {
                        mem.Write(extension, 0, 3);                          //E[I|N|S|C]F at beginning
                        mem.Write(Packet.EncodeNumber(Rid, 4), 0, 4);        //rid
                        mem.Write(Packet.EncodeNumber(Data.Count, 2), 0, 2); //len

                        Version = pubVersion;
                        mem.WriteByte(Packet.EncodeNumber(Version, 1)[0]);                         //new version check

                        for (int i = 1; i < Data.Count; ++i)
                        {
                            byte[] toWrite = Data[i].SerializeToByteArray();
                            mem.Write(toWrite, 0, toWrite.Length);
                        }
                    }

                    //write the data to the stream and overwrite whatever the rid is with the CRC
                    CRC32 crc    = new CRC32();
                    uint  newRid = crc.Check(allData, 7, (uint)allData.Length - 7);
                    Rid = (int)newRid;
                    sw.Write(allData, 0, allData.Length);
                    sw.Seek(4, SeekOrigin.Begin);
                    sw.Write(Packet.EncodeNumber(Rid, 4), 0, 4);
                }
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return(false);
            }

            error = "none";
            return(true);
        }
Example #14
0
        private void InstallThread(object ip)
        {
            if (Monitor.TryEnter(InstallThreadObject))
            {
                var  param      = ip as InstallThreadParam;
                bool onlyAdd    = param.onlyAdd;
                var  dispatcher = System.Windows.Deployment.Current.Dispatcher;
                if (OnInstallStateChanged != null)
                {
                    dispatcher.BeginInvoke(new Action(() =>
                    {
                        InstallEventArgs e = new InstallEventArgs();
                        e.onlyAdd          = onlyAdd;
                        e.busyState        = true;
                        e.song             = this;
                        OnInstallStateChanged(this, e);
                    }));
                }
                //InteropSvc.InteropLib.Instance.AddRingtoneFile(FilePath, "CustomRingtone2", _song.IsProtected ? 1 : 0, 0);

                if (FilePath.Contains("."))
                {
                    string newFilePath = CutTheSong(this, param.start, param.end);
                    if (newFilePath != null)
                    {
                        string extension = newFilePath.Substring(newFilePath.LastIndexOf(".") + 1);
                        string hash      = _song.ToString().GetHashCode().ToString("X");
                        InteropSvc.InteropLib.Instance.CopyFile7(newFilePath, "\\My Documents\\Ringtones\\CustomRingtone" + hash + "." + extension, false);
                        InteropSvc.InteropLib.Instance.RegistrySetString7(InteropSvc.InteropLib.HKEY_CURRENT_USER, "ControlPanel\\Sounds\\CustomRingtones", "CustomRingtone" + hash + "." + extension, Base.Name);
                        if (!onlyAdd)
                        {
                            InteropSvc.InteropLib.Instance.RegistrySetString7(InteropSvc.InteropLib.HKEY_CURRENT_USER, "ControlPanel\\Sounds\\RingTone0", "Sound", "\\My Documents\\Ringtones\\CustomRingtone" + hash + "." + extension);
                            InteropSvc.InteropLib.Instance.RegistrySetString7(InteropSvc.InteropLib.HKEY_CURRENT_USER, "ControlPanel\\Sounds\\RingTone1", "Sound", "\\My Documents\\Ringtones\\CustomRingtone" + hash + "." + extension);
                            InteropSvc.InteropLib.Instance.RegistrySetString7(InteropSvc.InteropLib.HKEY_CURRENT_USER, "ControlPanel\\Sounds\\RingTone2", "Sound", "\\My Documents\\Ringtones\\CustomRingtone" + hash + "." + extension);
                            InteropSvc.InteropLib.Instance.RegistrySetString7(InteropSvc.InteropLib.HKEY_CURRENT_USER, "ControlPanel\\Sounds\\RingTone3", "Sound", "\\My Documents\\Ringtones\\CustomRingtone" + hash + "." + extension);
                        }
                    }
                }

                if (OnInstallStateChanged != null)
                {
                    dispatcher.BeginInvoke(new Action(() =>
                    {
                        if (OnInstallStateChanged != null)
                        {
                            InstallEventArgs e = new InstallEventArgs();
                            e.busyState        = false;
                            e.song             = null;
                            e.onlyAdd          = onlyAdd;
                            OnInstallStateChanged(this, e);
                        }
                    }));
                }
                if (OnInstalled != null)
                {
                    dispatcher.BeginInvoke(new Action(() =>
                    {
                        OnInstalled(this, new EventArgs());
                    }));
                }

                Monitor.Exit(InstallThreadObject);
            }
        }
Example #15
0
 private bool FilePathIsValid()
 => string.IsNullOrWhiteSpace(FilePath) && (FilePath.Contains(@"\") || FilePath.Contains("/")) && FilePath.Length > 2;
Example #16
0
        //private static Uri addressNetwork;



        static void Main(string[] args)
        {
            Console.WriteLine("---------- FTP UPLOADER ----------");
            System.Threading.Thread.Sleep(500);


            Console.WriteLine("\nEnter filepath(s): ");
            Console.WriteLine("\nIf you want to upload multiple files, separate each file path with a comma(,)");
            Console.WriteLine();
            FilePath = Console.ReadLine();
            if (FilePath.Contains(','))
            {
                FilesPath = FilePath.Split(',');
                if (FilesPath.Length > 1 && !FilesPath.Contains(""))
                {
                    for (int i = 0; i < FilesPath.Length; i++)
                    {
                        bool fileExists = File.Exists(@FilesPath[i]);
                        while (!fileExists)
                        {
                            Console.WriteLine("\nThe file " + Path.GetFileName(FilesPath[i]) + " doesn't exist. Please enter a valid file path: ");
                            FilesPath[i] = Console.ReadLine();
                            fileExists   = File.Exists(FilesPath[i]);
                        }
                    }
                }
            }


            do
            {
                Console.WriteLine("\nEnter network path:");
                Console.WriteLine("\n(for example: 127.0.0.1:40/path/)");
                Console.WriteLine();
                NetworkPath = Console.ReadLine();
            }while (NetworkPath.Equals(""));


            Username = "";
            Console.WriteLine("\nEnter a valid username: "******"\b \b");
                    }
                }
            }while (keyUser.Key != ConsoleKey.Enter || Username.Equals(""));


            Password = "";
            Console.WriteLine();
            Console.WriteLine("\nEnter a valid password:"******"*");
                }
                else
                {
                    if (Password.Length > 0 && key.Key == ConsoleKey.Backspace)
                    {
                        Password = Password.Substring(0, (Password.Length - 1));


                        Console.Write("\b \b");
                    }
                }
            }while (key.Key != ConsoleKey.Enter || Password.Equals(""));



            Console.WriteLine();



            NetworkCredential netcred = new NetworkCredential(Username, Password);

            /* making sure the object is not null, is not empty, and the elements are not empty strings */
            if (FilesPath != null && FilesPath.Length != 0 && !FilesPath.Any(p => p.Equals("")))
            {
                bool[] results = new bool[FilesPath.Length];

                results.Populate(false);
                try
                {
                    results = FtpHelper.UploadFiles(FilesPath, NetworkPath, netcred);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error occurred.");
                    Console.WriteLine("\nException: " + ex.Message);

                    if (ex.InnerException != null)
                    {
                        Console.WriteLine("\nInnerException: " + ex.InnerException);
                    }
                    Console.WriteLine("\nPress any key to exit ...");
                    Console.ReadKey();
                    Environment.Exit(666);
                }
                if (!results.Any(p => !p))
                {
                    Console.WriteLine("\n   ---------------   ");
                    Console.WriteLine("\nFTP Upload successfully completed.");
                }
                else
                {
                    Console.WriteLine("\nFTP Upload was not completed successfully");
                }
            }
            else
            {
                if (FilePath.Contains(','))
                {
                    FilePath = FilePath.Replace(",", "");
                }
                bool result = false;
                try
                {
                    result = FtpHelper.UploadFiles(FilePath, NetworkPath, netcred);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error occurred.");
                    Console.WriteLine("\nException: " + ex.Message);

                    if (ex.InnerException != null)
                    {
                        Console.WriteLine("\nInnerException: " + ex.InnerException);
                    }
                    Console.WriteLine("\nPress any key to exit ...");
                    Console.ReadKey();
                    Environment.Exit(666);
                }
                if (result)
                {
                    Console.WriteLine("\n   ---------------   ");
                    Console.WriteLine("\nFTP Upload successfully completed.");
                }
                else
                {
                    Console.WriteLine("\nFTP Upload was not completed successfully");
                }
            }
            Console.WriteLine("\nPress any key to exit ...");
            Console.ReadKey();
        }