コード例 #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        /// <param name="directoryName"></param>
        /// <param name="extension"></param>
        /// <param name="removeOrig"></param>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        public static int RestoreOrigFiles(string directoryName, string extension, bool removeOrig)
        {
            int           numCopied   = 0;
            DirectoryInfo di          = new DirectoryInfo(directoryName);
            string        origPattern = CreateNewFileName("*" + extension, original);

            System.IO.FileInfo[] fi = di.GetFiles(origPattern);

            LogFile.AddLine("RestoreOrigFiles: " + directoryName + origPattern);

            foreach (System.IO.FileInfo f in fi)
            {
                string savedName = f.FullName;
                string defName   = UndoCreateNewFileName(savedName, original);
                try
                {
                    FileCopyWithLogging(savedName, defName, true);
                    if (removeOrig)
                    {
                        // delete the orig file here...
                        DeleteFile(savedName);
                    }
                    numCopied++;
                }
                catch
                {
                    LogFile.AddErrorLine("Error restoring " + original + " file: " + f.FullName);
                    throw new LDExceptions(ErrorCodes.FileWrite);
                }
            }
            if (numCopied == 0)
            {
                LogFile.AddLine("RestoreOrigFiles: No files copied.");
            }

            return(numCopied);
        }
コード例 #2
0
        public static int Main(string[] args)
        {
            LogFile.AddLine("================= Start of process =================");
            LogFile.AddLine("Command line: <" + Environment.CommandLine + ">");
            bool testedLock = false;

            ErrorCodes ret = ErrorCodes.None;

            try
            {
                CommandLineParser             argParser   = new CommandLineParser();
                CommandLineParser.ParseResult parseResult = argParser.Parse(args);
                switch (parseResult)
                {
                case CommandLineParser.ParseResult.error:
                    ret = ErrorCodes.CommandLine;
                    int iRet = (int)ErrorCodes.CommandLine;
                    LogFile.Release();
                    return(iRet);

                case CommandLineParser.ParseResult.stop:
                    LogFile.Release();
                    // no error - success
                    return((int)(ErrorCodes.Success));
                }

                // tests the command line parser to make sure we have valid data
                if (argParser.FlagUsed(CommandLineParser.Flag.dontDoAnything))
                {
                    foreach (CommandLineParser.Flag flag in argParser.FlagsUsed())
                    {
                        Console.Write("{0}:{1}, ", flag.ToString(), argParser.FlagData(flag));
                    }
                    Console.WriteLine();
                    return((int)ErrorCodes.Success);
                }

                // don't restrict the GUI
                bool runSilent = false;
                if (argParser.FlagUsed(CommandLineParser.Flag.q))
                {
                    runSilent = true;
                }

                bool slow = false;
                // Use the old slower file reading method
                if (argParser.FlagUsed(CommandLineParser.Flag.slow))
                {
                    slow = true;
                }

                if (argParser.FlagUsed(CommandLineParser.Flag.testMainParserRoutine))
                {
                    LocaleFileClass localeObject   = new LocaleFileClass();
                    bool            successParsing = localeObject.TestBaseLocaleParsers(false);
                    if (successParsing)
                    {
                        ret = ErrorCodes.Success;
                    }
                    else
                    {
                        ret = ErrorCodes.LDParsingError;
                    }
                }


                if (argParser.FlagUsed(CommandLineParser.Flag.testICUDataParser))
                {
                    try
                    {
                        IcuDataNode.TestIcuDataNode(argParser.FlagData(CommandLineParser.Flag.testICUDataParser));
                        ret = ErrorCodes.Success;
                    }
                    catch (LDExceptions e)
                    {
                        ret = e.ec;
                        LogFile.AddErrorLine("LDException: " + e.ec.ToString() + "-" + Error.Text(e.ec));
                        if (e.HasConstructorText)
                        {
                            LogFile.AddErrorLine("LDException Msg: " + e.ConstructorText);
                        }
                    }
                    catch (System.Exception e)
                    {
                        ret = ErrorCodes.NonspecificError;
                        LogFile.AddErrorLine(e.Message);
                        LogFile.AddErrorLine(e.StackTrace);
                    }
                }

                if (argParser.FlagUsed(CommandLineParser.Flag.s))
                {
                    LocaleFileClass localeObject = new LocaleFileClass();
                    localeObject.RunSilent = runSilent;
                    ret = localeObject.ShowCustomLocales();
                }

                if (argParser.FlagUsed(CommandLineParser.Flag.customLanguages))
                {
                    LocaleFileClass localeObject = new LocaleFileClass();
                    localeObject.RunSilent = runSilent;
                    ret = localeObject.ShowCustomLanguages();
                }

                if (argParser.FlagUsed(CommandLineParser.Flag.o))                       // restore origs'
                {
                    CallingID cid = CallingID.CID_RESTORE;
                    if (argParser.FlagUsed(CommandLineParser.Flag.newlang))
                    {
                        cid = CallingID.CID_NEW;                                // internal new lang case
                    }
                    if (!CheckForIcuLocked(null, runSilent, cid))
                    {
                        return((int)ErrorCodes.CancelAccessFailure);
                    }
                    testedLock = true;
                    // only perform this command by itself even if given with other options
                    LocaleFileClass restoreFiles = new LocaleFileClass();
                    restoreFiles.RunSlow   = slow;
                    restoreFiles.RunSilent = runSilent;
                    // Restore all the original files, installing the PUA characters if requested.
                    ret = restoreFiles.RestoreOrigFiles(true);

                    // LT-5374 : wasn't moving the res files from the Icu34 dir to the Icudt34l dir
                    if (ret == ErrorCodes.Success)
                    {
                        // remove the backup files from the undo/recover file name list
                        restoreFiles.RemoveBackupFiles();
                    }
                    restoreFiles.RemoveTempFiles();
                    restoreFiles.MoveNewResFilesToSubDir();
                }

                if (argParser.FlagUsed(CommandLineParser.Flag.r))                       // remove locale
                {
                    if (!testedLock && !CheckForIcuLocked(argParser.FlagData(CommandLineParser.Flag.r), runSilent, CallingID.CID_REMOVE))
                    {
                        return((int)ErrorCodes.CancelAccessFailure);
                    }
                    testedLock = true;
                    string deleteLocale = argParser.FlagData(CommandLineParser.Flag.r);
                    argParser.RemoveFlag(CommandLineParser.Flag.r);
                    bool rUsed = argParser.FlagUsed(CommandLineParser.Flag.r);

                    LocaleFileClass removeLocaleObject = new LocaleFileClass();
                    try
                    {
                        removeLocaleObject.RunSilent = runSilent;
                        ret = removeLocaleObject.RemoveLocale(deleteLocale);
                        removeLocaleObject.MoveNewResFilesToSubDir();
                    }
                    catch (System.Exception e)
                    {
                        ret = ErrorCodes.NonspecificError;

                        LogFile.AddErrorLine(e.Message);
                        LogFile.AddErrorLine(e.StackTrace);
                        LogFile.AddErrorLine("Exception: " + ret.ToString() + "-" + Error.Text(ret));
                        removeLocaleObject.RestoreFiles();                              // copy backup files to original files.
                    }
                }
                // install locale
                if ((ret == ErrorCodes.Success || ret == ErrorCodes.None) &&
                    argParser.FlagUsed(CommandLineParser.Flag.i))
                {
                    CallingID cid = CallingID.CID_INSTALL;
                    if (argParser.FlagUsed(CommandLineParser.Flag.newlang))
                    {
                        cid = CallingID.CID_NEW;                                // internal new lang case
                    }
                    if (!testedLock && !CheckForIcuLocked(
                            argParser.FlagData(CommandLineParser.Flag.i), runSilent, cid))
                    {
                        return((int)ErrorCodes.CancelAccessFailure);
                    }
                    testedLock = true;
                    LocaleFileClass localeFileObject = new LocaleFileClass();
                    localeFileObject.RunSilent = runSilent;
                    localeFileObject.RunSlow   = slow;
                    try
                    {
                        string addLocale = argParser.FlagData(CommandLineParser.Flag.i);
                        localeFileObject.InstallLDFile(addLocale);
                        ret = ErrorCodes.Success;
                    }
                    catch (LDExceptions e)
                    {
                        localeFileObject.RestoreFiles();                                // copy backup files to original files.
                        ret = e.ec;
                        LogFile.AddErrorLine("LDException: " + e.ec.ToString() + "-" + Error.Text(e.ec));
                        if (e.HasConstructorText)
                        {
                            LogFile.AddErrorLine("LDException Msg: " + e.ConstructorText);
                        }
                    }
                    catch (System.Exception e)
                    {
                        ret = ErrorCodes.NonspecificError;

                        LogFile.AddErrorLine(e.Message);
                        LogFile.AddErrorLine(e.StackTrace);
                        LogFile.AddErrorLine("Exception: " + ret.ToString() + "-" + Error.Text(ret));
                        localeFileObject.RestoreFiles();                                // copy backup files to original files.
                    }

                    if (ret == ErrorCodes.Success)
                    {
                        // remove the backup files from the undo/recover file name list
                        localeFileObject.RemoveBackupFiles();
                    }

                    localeFileObject.RemoveTempFiles();
                    localeFileObject.MoveNewResFilesToSubDir();
                }

                //Add PUA Character
                if ((ret == ErrorCodes.Success || ret == ErrorCodes.None) &&
                    argParser.FlagUsed(CommandLineParser.Flag.c))
                {
                    if (!testedLock && !CheckForIcuLocked(argParser.FlagData(CommandLineParser.Flag.c), runSilent, CallingID.CID_UNKNOWN))
                    {
                        return((int)ErrorCodes.CancelAccessFailure);
                    }
                    LocaleFileClass localeFileObject = new LocaleFileClass();
                    localeFileObject.RunSilent = runSilent;
                    try
                    {
                        string addLocale = argParser.FlagData(CommandLineParser.Flag.c);
                        localeFileObject.InstallPUACharacters(addLocale);
                        ret = ErrorCodes.Success;
                    }
                    catch (LDExceptions e)
                    {
                        // copy backup files to original files.
                        localeFileObject.RestoreFiles();
                        ret = e.ec;
                        LogFile.AddErrorLine("LDException: " + e.ec.ToString() + "-" + Error.Text(e.ec));
                        if (e.HasConstructorText)
                        {
                            LogFile.AddErrorLine("LDException Msg: " + e.ConstructorText);
                        }
                    }
                    catch (System.Exception e)
                    {
                        ret = ErrorCodes.NonspecificError;
                        LogFile.AddErrorLine("Exception: " + e.Message);
                        LogFile.AddErrorLine(e.StackTrace);
                        LogFile.AddErrorLine("Error Code: " + ret.ToString() + "-" + Error.Text(ret));
                        localeFileObject.RestoreFiles();                                // copy backup files to original files.
                    }
                    if (ret == ErrorCodes.Success)
                    {
                        // remove the backup files from the undo/recover file name list
                        localeFileObject.RemoveBackupFiles();
                    }

                    localeFileObject.RemoveTempFiles();
                }

                if (ret == ErrorCodes.Success)
                {
                    if (argParser.FlagUsed(CommandLineParser.Flag.q))
                    {
                        LogFile.AddLine("--- Success ---");
                    }
                    else
                    {
                        LogFile.AddErrorLine("--- Success ---");
                    }
                }
            }
            catch (System.Exception e)
            {
                ret = ErrorCodes.NonspecificError;
                LogFile.AddErrorLine("Exception: " + e.Message + " " + e.StackTrace);
                LogFile.AddErrorLine("Exception: " + ret.ToString() + "-" + Error.Text(ret));
            }
            finally
            {
                LogFile.Release();
            }

            int nret = (int)ret;

            return(nret);
        }
コード例 #3
0
        /// <summary>
        /// Check for locked ICU files and return
        /// </summary>
        /// <param name="localPath">the locale being modified. May just be the ICULocale name, or
        /// may be a fully specified path name to the language xml file, or null.</param>
        /// <param name="runSilent">Boolean set to true if we don't want to ask the user for info.
        /// <returns>true if ok to continue, or false if files are locked</returns>
        private static bool CheckForIcuLocked(string inputLocale, bool runSilent, CallingID caller)
        {
            bool   fOk;
            string locale = null;

            if (inputLocale != null)
            {
                int    icuName    = inputLocale.LastIndexOf("\\");
                string icuPortion = inputLocale.Substring(icuName + 1);
                int    iLocale    = icuPortion.LastIndexOf(".");
                if (iLocale < 0)
                {
                    iLocale = icuPortion.Length;
                }
                locale = icuPortion.Substring(0, iLocale);
            }
            do
            {
                fOk = true;
                string lockedFile = Icu.CheckIcuLocked(locale);
                if (lockedFile != null)
                {
                    LogFile.AddLine(" File Access Error: " + lockedFile + ". Asking user to Retry or Cancel. Caller=" + caller.ToString());
                    if (runSilent)
                    {
                        LogFile.AddLine(" Silently cancelled operation.");
                        System.Console.WriteLine("Silently cancelled operation.");
                        return(false);
                    }
                    string message = "";                        // for now
                    string nl      = Environment.NewLine;
                    switch (caller)
                    {
                    case CallingID.CID_RESTORE:
                        message = String.Format(InstallLanguageStrings.ksRestore_CloseOtherFWApps,
                                                lockedFile);
                        break;

                    case CallingID.CID_NEW:
                        message = String.Format(InstallLanguageStrings.ksNew_CloseOtherFWApps,
                                                locale, lockedFile);
                        break;

                    case CallingID.CID_INSTALL:
                    case CallingID.CID_REMOVE:
                    case CallingID.CID_UNKNOWN:
                    case CallingID.CID_UPDATE:
                    default:
                        message = String.Format(InstallLanguageStrings.ksUpdate_CloseOtherFWApps,
                                                locale, lockedFile);
                        break;
                    }
                    message = message + nl + nl +
                              InstallLanguageStrings.ksCloseClipboardConverter + nl + nl +
                              InstallLanguageStrings.ksCloseThisFWApp;

                    string                  caption   = InstallLanguageStrings.ksInstallLanguageMsgCaption;
                    MessageBoxButtons       buttons   = MessageBoxButtons.RetryCancel;
                    MessageBoxIcon          icon      = MessageBoxIcon.Exclamation;
                    MessageBoxDefaultButton defButton = MessageBoxDefaultButton.Button1;
                    DialogResult            result    = MessageBox.Show(message, caption, buttons, icon, defButton);
                    if (result == DialogResult.Cancel)
                    {
                        LogFile.AddLine(" User cancelled operation.");
                        System.Console.WriteLine("User cancelled operation.");
                        return(false);
                    }
                    else
                    {
                        fOk = false;
                    }
                }
            } while (fOk == false);
            return(true);
        }